C# Class Tp.Utils.Html.PlainTextRenderer

A specialized sanitizer which outputs formatted plain text instead of HTML.
The renderer removes extra whitespace, and converts block level HTML elements to lines of plain text.
Inheritance: Sanitizer
显示文件 Open project: TargetProcess/Target-Process-Plugins Class Usage Examples

Protected Properties

Property Type Description
_newLineStarted bool
_whiteSpaceStarted bool

Public Methods

Method Description
RenderToPlainText ( string input, string newLine = "\n" ) : string

Converts HTML to plain text.

Warning, the returned text may contain HTML fragments!!! For example, the original HTML code is: <p>&lt;hello&lt;>/p> Then, the converted text will be: <hello> So if you intend to output the stripped text in HTML, you need encode it first!

Protected Methods

Method Description
AfterDocument ( TextWriter result ) : void
BeforeDocument ( TextWriter result ) : void
RenderText ( TextWriter result, string value ) : void
StartNewLine ( 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

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

RenderText() protected method

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

RenderToPlainText() public static method

Converts HTML to plain text.
Warning, the returned text may contain HTML fragments!!! For example, the original HTML code is: <p>&lt;hello&lt;>/p> Then, the converted text will be: <hello> So if you intend to output the stripped text in HTML, you need encode it first!
public static RenderToPlainText ( string input, string newLine = "\n" ) : string
input string Input HTML. May be null.
newLine string The line terminator string
return string

StartNewLine() protected method

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

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

_newLineStarted protected_oe property

If new line has already been written.
protected bool _newLineStarted
return bool

_whiteSpaceStarted protected_oe property

Whether currently outputing whitespace.
protected bool _whiteSpaceStarted
return bool