C# Class Tp.Utils.Html.Sanitizer

Clean up HTML code, remove dangerous fragments, such as styles, scripts, event attributes, forms, etc...
IDEA: Use HtmlTextWriter from the .NET framework to write resulting HTML code.
显示文件 Open project: TargetProcess/Target-Process-Plugins

Protected Properties

Property Type Description
AutoClosedTags HashSet
EmptyTags HashSet
EventAttributes HashSet
ExcludeTags HashSet
IgnoreTags HashSet
IncludeTags HashSet
RewriteTags string>.IDictionary
UntouchableAttributes HashSet
_enabled bool
_tags List

Public Methods

Method Description
ClearMarkdownTag ( string input ) : string
FormatComment ( string text ) : string
IsMarkdown ( string input ) : bool
Process ( string input ) : string
Sanitize ( string input ) : string

Sanitize input HTML using default settings.

Sanitize ( TextReader input, TextWriter result ) : void
Sanitizer ( ) : System
TextToHtml ( string text ) : string

Htmlize text, that is replace new line with <br/>, etc.

This method will try to sniff whether the original text is already a html document.

Protected Methods

Method Description
AfterDocument ( TextWriter result ) : void
BeforeDocument ( TextWriter result ) : void
CaseCData ( HtmlReader htmlReader, TextWriter result ) : void
CaseElement ( HtmlReader htmlReader, TextWriter result ) : void
CaseEndElement ( HtmlReader htmlReader, TextWriter result ) : void
CaseText ( HtmlReader htmlReader, TextWriter result ) : void
CheckStack ( ) : void
FuzzyPopTag ( string item ) : bool

Finds the specified tag somewhere in the stack and removes it from there.

HtmlAttributeEncode ( string value, TextWriter writer ) : void
HtmlEncode ( string value, TextWriter writer ) : void
IsValidAttribute ( string name, string key, string value ) : bool
PopTag ( ) : string
Reset ( ) : void

Reset internal state left from previous run.

RewriteTag ( string tagName ) : string

Checks for rewrite and rewrites tag if necessary

Sanitize ( HtmlReader htmlReader, TextWriter result ) : void
WriteCData ( TextWriter result, string value ) : void
WriteElement ( TextWriter result, string name, string>.Dictionary attributes, bool empty ) : void
WriteEndElement ( TextWriter result, string name ) : void
WriteText ( TextWriter result, string value ) : void

Private Methods

Method Description
PushTag ( string item ) : void

Method Details

AfterDocument() protected method

protected AfterDocument ( TextWriter result ) : void
result System.IO.TextWriter
return void

BeforeDocument() protected method

protected BeforeDocument ( TextWriter result ) : void
result System.IO.TextWriter
return void

CaseCData() protected method

protected CaseCData ( HtmlReader htmlReader, TextWriter result ) : void
htmlReader HtmlReader
result System.IO.TextWriter
return void

CaseElement() protected method

protected CaseElement ( HtmlReader htmlReader, TextWriter result ) : void
htmlReader HtmlReader
result System.IO.TextWriter
return void

CaseEndElement() protected method

protected CaseEndElement ( HtmlReader htmlReader, TextWriter result ) : void
htmlReader HtmlReader
result System.IO.TextWriter
return void

CaseText() protected method

protected CaseText ( HtmlReader htmlReader, TextWriter result ) : void
htmlReader HtmlReader
result System.IO.TextWriter
return void

CheckStack() protected method

protected CheckStack ( ) : void
return void

ClearMarkdownTag() public static method

public static ClearMarkdownTag ( string input ) : string
input string
return string

FormatComment() public static method

public static FormatComment ( string text ) : string
text string
return string

FuzzyPopTag() protected method

Finds the specified tag somewhere in the stack and removes it from there.
protected FuzzyPopTag ( string item ) : bool
item string Item to remove.
return bool

HtmlAttributeEncode() protected method

protected HtmlAttributeEncode ( string value, TextWriter writer ) : void
value string
writer System.IO.TextWriter
return void

HtmlEncode() protected method

protected HtmlEncode ( string value, TextWriter writer ) : void
value string
writer System.IO.TextWriter
return void

IsMarkdown() public static method

public static IsMarkdown ( string input ) : bool
input string
return bool

IsValidAttribute() protected method

protected IsValidAttribute ( string name, string key, string value ) : bool
name string
key string
value string
return bool

PopTag() protected method

protected PopTag ( ) : string
return string

Process() public method

public Process ( string input ) : string
input string
return string

Reset() protected method

Reset internal state left from previous run.
protected Reset ( ) : void
return void

RewriteTag() protected method

Checks for rewrite and rewrites tag if necessary
protected RewriteTag ( string tagName ) : string
tagName string
return string

Sanitize() public static method

Sanitize input HTML using default settings.
public static Sanitize ( string input ) : string
input string Input HTML. May be null.
return string

Sanitize() protected method

protected Sanitize ( HtmlReader htmlReader, TextWriter result ) : void
htmlReader HtmlReader
result System.IO.TextWriter
return void

Sanitize() public method

public Sanitize ( TextReader input, TextWriter result ) : void
input System.IO.TextReader
result System.IO.TextWriter
return void

Sanitizer() public method

public Sanitizer ( ) : System
return System

TextToHtml() public static method

Htmlize text, that is replace new line with <br/>, etc.
This method will try to sniff whether the original text is already a html document.
public static TextToHtml ( string text ) : string
text string Original text, may be null.
return string

WriteCData() protected method

protected WriteCData ( TextWriter result, string value ) : void
result System.IO.TextWriter
value string
return void

WriteElement() protected method

protected WriteElement ( TextWriter result, string name, string>.Dictionary attributes, bool empty ) : void
result System.IO.TextWriter
name string
attributes string>.Dictionary
empty bool
return void

WriteEndElement() protected method

protected WriteEndElement ( TextWriter result, string name ) : void
result System.IO.TextWriter
name string
return void

WriteText() protected method

protected WriteText ( TextWriter result, string value ) : void
result System.IO.TextWriter
value string
return void

Property Details

AutoClosedTags protected_oe property

These tags may not be explicitly closed, but presense of a new open tag automaticaly closes the previously open but not closed tag.
protected HashSet AutoClosedTags
return HashSet

EmptyTags protected_oe property

These tags need not be closed explicitly.
protected HashSet EmptyTags
return HashSet

EventAttributes protected_oe property

Attributes to be suppressed.
protected HashSet EventAttributes
return HashSet

ExcludeTags protected_oe property

Tags whose outer html to be suppressed. In other words, entire tag with its content will be suppressed.
protected HashSet ExcludeTags
return HashSet

IgnoreTags protected_oe property

Write inner instead of outer html for these tags. In other words, write tag content without tag.
protected HashSet IgnoreTags
return HashSet

IncludeTags protected_oe property

Overrides suppression caused by the tags above, enables outer html.
protected HashSet IncludeTags
return HashSet

RewriteTags protected_oe property

Rewrite some (obsolete, deprecated) tags to another tags.
protected IDictionary RewriteTags
return string>.IDictionary

UntouchableAttributes protected_oe property

Untouchable attributes.
protected HashSet UntouchableAttributes
return HashSet

_enabled protected_oe property

Whether to write elements.
protected bool _enabled
return bool

_tags protected_oe property

Stack with tags.
protected List _tags
return List