C# 클래스 Yuhan.WPF.XamlToHtmlParser.HtmlToXamlConverter

HtmlToXamlConverter is a static class that takes an HTML string and converts it into XAML
파일 보기 프로젝트 열기: hansuky/Yuhan

공개 메소드들

메소드 설명
ConvertHtmlToXaml ( string htmlString, bool asFlowDocument ) : string

Converts an html string into xaml string.

GetAttribute ( XmlElement element, string attributeName ) : string

Returns a value for an attribute by its name (ignoring casing)

비공개 메소드들

메소드 설명
AddBlock ( XmlElement xamlParentElement, XmlNode htmlNode, Hashtable inheritedProperties, CssStylesheet stylesheet, List sourceContext ) : XmlNode

Analyzes the given htmlElement expecting it to be converted into some of xaml Block elements and adds the converted block to the children collection of xamlParentElement. Analyzes the given XmlElement htmlElement, recognizes it as some HTML element and adds it as a child to a xamlParentElement. In some cases several following siblings of the given htmlElement will be consumed too (e.g. LIs encountered without wrapping UL/OL, which must be collected together and wrapped into one implicit List element).

AddBreak ( XmlElement xamlParentElement, string htmlElementName ) : void
AddColumnInformation ( XmlElement htmlTableElement, XmlElement xamlTableElement, ArrayList columnStartsAllRows, Hashtable currentProperties, CssStylesheet stylesheet, List sourceContext ) : void

Processes the information about table columns - COLGROUP and COL html elements.

AddDataToTableCell ( XmlElement xamlTableCellElement, XmlNode htmlDataStartNode, Hashtable currentProperties, CssStylesheet stylesheet, List sourceContext ) : void

adds table cell data to xamlTableCellElement

AddHyperlink ( XmlElement xamlParentElement, XmlElement htmlElement, Hashtable inheritedProperties, CssStylesheet stylesheet, List sourceContext ) : void
AddImage ( XmlElement xamlParentElement, XmlElement htmlElement, Hashtable inheritedProperties, CssStylesheet stylesheet, List sourceContext ) : void
AddImplicitParagraph ( XmlElement xamlParentElement, XmlNode htmlNode, Hashtable inheritedProperties, CssStylesheet stylesheet, List sourceContext ) : XmlNode

Creates a Paragraph element and adds all nodes starting from htmlNode converted to appropriate Inlines.

AddInline ( XmlElement xamlParentElement, XmlNode htmlNode, Hashtable inheritedProperties, CssStylesheet stylesheet, List sourceContext ) : void
AddList ( XmlElement xamlParentElement, XmlElement htmlListElement, Hashtable inheritedProperties, CssStylesheet stylesheet, List sourceContext ) : void

Converts Html ul or ol element into Xaml list element. During conversion if the ul/ol element has any children that are not li elements, they are ignored and not added to the list element

AddListItem ( XmlElement xamlListElement, XmlElement htmlLIElement, Hashtable inheritedProperties, CssStylesheet stylesheet, List sourceContext ) : void

Converts htmlLIElement into Xaml ListItem element, and appends it to the parent xamlListElement

AddOrphanListItems ( XmlElement xamlParentElement, XmlElement htmlLIElement, Hashtable inheritedProperties, CssStylesheet stylesheet, List sourceContext ) : XmlElement

If li items are found without a parent ul/ol element in Html string, creates xamlListElement as their parent and adds them to it. If the previously added node to the same xamlParentElement was a List, adds the elements to that list. Otherwise, we create a new xamlListElement and add them to it. Elements are added as long as li elements appear sequentially. The first non-li or text node stops the addition.

AddParagraph ( XmlElement xamlParentElement, XmlElement htmlElement, Hashtable inheritedProperties, CssStylesheet stylesheet, List sourceContext ) : void

Generates Paragraph element from P, H1-H7, Center etc.

AddSection ( XmlElement xamlParentElement, XmlElement htmlElement, Hashtable inheritedProperties, CssStylesheet stylesheet, List sourceContext ) : void

Generates Section or Paragraph element from DIV depending whether it contains any block elements or not

AddSpanOrRun ( XmlElement xamlParentElement, XmlElement htmlElement, Hashtable inheritedProperties, CssStylesheet stylesheet, List sourceContext ) : void
AddTable ( XmlElement xamlParentElement, XmlElement htmlTableElement, Hashtable inheritedProperties, CssStylesheet stylesheet, List sourceContext ) : void

Converts htmlTableElement to a Xaml Table element. Adds tbody elements if they are missing so that a resulting Xaml Table element is properly formed.

AddTableCellsToTableRow ( XmlElement xamlTableRowElement, XmlNode htmlTDStartNode, Hashtable currentProperties, ArrayList columnStarts, ArrayList activeRowSpans, CssStylesheet stylesheet, List sourceContext ) : XmlNode

Adds TableCell elements to xamlTableRowElement.

AddTableColumn ( XmlElement xamlTableElement, XmlElement htmlColElement, Hashtable inheritedProperties, CssStylesheet stylesheet, List sourceContext ) : void

Converts htmlColElement into Xaml TableColumn element, and appends it to the parent xamlTableColumnGroupElement

AddTableColumnGroup ( XmlElement xamlTableElement, XmlElement htmlColgroupElement, Hashtable inheritedProperties, CssStylesheet stylesheet, List sourceContext ) : void

Converts htmlColgroupElement into Xaml TableColumnGroup element, and appends it to the parent xamlTableElement

AddTableRowsToTableBody ( XmlElement xamlTableBodyElement, XmlNode htmlTRStartNode, Hashtable currentProperties, ArrayList columnStarts, CssStylesheet stylesheet, List sourceContext ) : XmlNode

Adds TableRow elements to xamlTableBodyElement. The rows are converted from Html tr elements that may be the children of an Html tbody element or an Html table element with tbody missing

AddTextRun ( XmlElement xamlElement, string textData ) : void
AnalyzeTRStructure ( XmlElement htmlTRElement, ArrayList columnStarts, ArrayList activeRowSpans, double tableWidth, CssStylesheet stylesheet ) : double

Performs a parsing pass over a tr element to read information about column width and rowspan attributes.

AnalyzeTableStructure ( XmlElement htmlTableElement, CssStylesheet stylesheet ) : ArrayList

Performs a parsing pass over a table to read information about column width and rowspan attributes. This information is used to determine the starting point of each column.

AnalyzeTbodyStructure ( XmlElement htmlTbodyElement, ArrayList columnStarts, ArrayList activeRowSpans, double tableWidth, CssStylesheet stylesheet ) : double

Performs a parsing pass over a tbody to read information about column width and rowspan attributes. Information read about width attributes is stored in the reference ArrayList parameter columnStarts, which contains a list of all starting positions of all columns in the table, ordered from left to right. Row spans are taken into consideration when computing column starts

ApplyLocalProperties ( XmlElement xamlElement, Hashtable localProperties, bool isBlock ) : void

Analyzes local properties of Html element, converts them into Xaml equivalents, and applies them to xamlElement

ApplyPropertiesToTableCellElement ( XmlElement htmlChildNode, XmlElement xamlTableCellElement ) : void

Applies properties to xamlTableCellElement based on the html td element it is converted from.

TODO: Use the processed properties for htmlChildNode instead of using the node itself

CalculateColumnSpan ( int columnIndex, double columnWidth, ArrayList columnStarts ) : int

Calculates column span based the column width and the widths of all other columns. Returns an integer representing the column span

ClearActiveRowSpans ( ArrayList activeRowSpans ) : void

Used for clearing activeRowSpans array in the beginning/end of each tbody

ComposeThicknessProperty ( XmlElement xamlElement, string propertyName, string left, string right, string top, string bottom ) : void
DefineInlineFragmentParent ( XmlComment htmlComment, XmlElement xamlParentElement ) : void
ExtractInlineFragment ( XmlElement xamlFlowDocumentElement ) : XmlElement
GetCellFromSingleCellTable ( XmlElement htmlTableElement ) : XmlElement
GetColorValue ( string colorValue ) : string
GetColumnWidth ( XmlElement htmlTDElement ) : double
GetCssAttribute ( string cssStyle, string attributeName ) : string

Extracts a value of css attribute from css style definition.

GetElementProperties ( XmlElement htmlElement, Hashtable inheritedProperties, Hashtable &localProperties, CssStylesheet stylesheet, List sourceContext ) : Hashtable

Analyzes the tag of the htmlElement and infers its associated formatted properties. After that parses style attribute and adds all inline css styles. The resulting style attributes are collected in output parameter localProperties.

GetNextColumnIndex ( int columnIndex, double columnWidth, ArrayList columnStarts, ArrayList activeRowSpans ) : int

Gets index at which a column should be inseerted into the columnStarts ArrayList. This is decided by the value columnStart. The columnStarts ArrayList is ordered in ascending order. Returns an integer representing the index at which the column should be inserted

GetNextColumnStart ( XmlElement htmlTDElement, double columnStart ) : double

Calculates width of next TD element based on starting position of current element and it's width, which is calculated byt he function

GetRowSpan ( XmlElement htmlTDElement ) : int

Gets row span attribute from htmlTDElement. Returns an integer representing the value of the rowspan attribute. Default value if attribute is not specified or if it is invalid is 1

InitializeActiveRowSpans ( ArrayList activeRowSpans, int count ) : void

Used for initializing activeRowSpans array in the before adding rows to tbody element

SetPropertyValue ( XmlElement xamlElement, DependencyProperty property, string stringValue ) : void
TryGetLengthValue ( string lengthAsString, double &length ) : bool

Converts a length value from string representation to a double.

UnQuote ( string value ) : string

Returns string extracted from quotation marks

VerifyColumnStartsAscendingOrder ( ArrayList columnStarts ) : void

Verifies that values in columnStart, which represent starting coordinates of all columns, are arranged in ascending order

메소드 상세

ConvertHtmlToXaml() 공개 정적인 메소드

Converts an html string into xaml string.
public static ConvertHtmlToXaml ( string htmlString, bool asFlowDocument ) : string
htmlString string /// Input html which may be badly formated xml. ///
asFlowDocument bool /// true indicates that we need a FlowDocument as a root element; /// false means that Section or Span elements will be used /// dependeing on StartFragment/EndFragment comments locations. ///
리턴 string

GetAttribute() 공개 정적인 메소드

Returns a value for an attribute by its name (ignoring casing)
public static GetAttribute ( XmlElement element, string attributeName ) : string
element XmlElement /// XmlElement in which we are trying to find the specified attribute ///
attributeName string /// String representing the attribute name to be searched for ///
리턴 string