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.
Afficher le fichier Open project: TargetProcess/Target-Process-Plugins

Protected Properties

Свойство Type Description
AutoClosedTags HashSet
EmptyTags HashSet
EventAttributes HashSet
ExcludeTags HashSet
IgnoreTags HashSet
IncludeTags HashSet
RewriteTags string>.IDictionary
UntouchableAttributes HashSet
_enabled bool
_tags List

Méthodes publiques

Méthode 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.

Méthodes protégées

Méthode 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

Méthode Description
PushTag ( string item ) : void

Method Details

AfterDocument() protected méthode

protected AfterDocument ( TextWriter result ) : void
result System.IO.TextWriter
Résultat void

BeforeDocument() protected méthode

protected BeforeDocument ( TextWriter result ) : void
result System.IO.TextWriter
Résultat void

CaseCData() protected méthode

protected CaseCData ( HtmlReader htmlReader, TextWriter result ) : void
htmlReader HtmlReader
result System.IO.TextWriter
Résultat void

CaseElement() protected méthode

protected CaseElement ( HtmlReader htmlReader, TextWriter result ) : void
htmlReader HtmlReader
result System.IO.TextWriter
Résultat void

CaseEndElement() protected méthode

protected CaseEndElement ( HtmlReader htmlReader, TextWriter result ) : void
htmlReader HtmlReader
result System.IO.TextWriter
Résultat void

CaseText() protected méthode

protected CaseText ( HtmlReader htmlReader, TextWriter result ) : void
htmlReader HtmlReader
result System.IO.TextWriter
Résultat void

CheckStack() protected méthode

protected CheckStack ( ) : void
Résultat void

ClearMarkdownTag() public static méthode

public static ClearMarkdownTag ( string input ) : string
input string
Résultat string

FormatComment() public static méthode

public static FormatComment ( string text ) : string
text string
Résultat string

FuzzyPopTag() protected méthode

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

HtmlAttributeEncode() protected méthode

protected HtmlAttributeEncode ( string value, TextWriter writer ) : void
value string
writer System.IO.TextWriter
Résultat void

HtmlEncode() protected méthode

protected HtmlEncode ( string value, TextWriter writer ) : void
value string
writer System.IO.TextWriter
Résultat void

IsMarkdown() public static méthode

public static IsMarkdown ( string input ) : bool
input string
Résultat bool

IsValidAttribute() protected méthode

protected IsValidAttribute ( string name, string key, string value ) : bool
name string
key string
value string
Résultat bool

PopTag() protected méthode

protected PopTag ( ) : string
Résultat string

Process() public méthode

public Process ( string input ) : string
input string
Résultat string

Reset() protected méthode

Reset internal state left from previous run.
protected Reset ( ) : void
Résultat void

RewriteTag() protected méthode

Checks for rewrite and rewrites tag if necessary
protected RewriteTag ( string tagName ) : string
tagName string
Résultat string

Sanitize() public static méthode

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

Sanitize() protected méthode

protected Sanitize ( HtmlReader htmlReader, TextWriter result ) : void
htmlReader HtmlReader
result System.IO.TextWriter
Résultat void

Sanitize() public méthode

public Sanitize ( TextReader input, TextWriter result ) : void
input System.IO.TextReader
result System.IO.TextWriter
Résultat void

Sanitizer() public méthode

public Sanitizer ( ) : System
Résultat System

TextToHtml() public static méthode

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.
Résultat string

WriteCData() protected méthode

protected WriteCData ( TextWriter result, string value ) : void
result System.IO.TextWriter
value string
Résultat void

WriteElement() protected méthode

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

WriteEndElement() protected méthode

protected WriteEndElement ( TextWriter result, string name ) : void
result System.IO.TextWriter
name string
Résultat void

WriteText() protected méthode

protected WriteText ( TextWriter result, string value ) : void
result System.IO.TextWriter
value string
Résultat 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
Résultat HashSet

EmptyTags protected_oe property

These tags need not be closed explicitly.
protected HashSet EmptyTags
Résultat HashSet

EventAttributes protected_oe property

Attributes to be suppressed.
protected HashSet EventAttributes
Résultat 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
Résultat 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
Résultat HashSet

IncludeTags protected_oe property

Overrides suppression caused by the tags above, enables outer html.
protected HashSet IncludeTags
Résultat HashSet

RewriteTags protected_oe property

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

UntouchableAttributes protected_oe property

Untouchable attributes.
protected HashSet UntouchableAttributes
Résultat HashSet

_enabled protected_oe property

Whether to write elements.
protected bool _enabled
Résultat bool

_tags protected_oe property

Stack with tags.
protected List _tags
Résultat List