本文整理汇总了C#中HTMLConverter.CssStylesheet类的典型用法代码示例。如果您正苦于以下问题:C# CssStylesheet类的具体用法?C# CssStylesheet怎么用?C# CssStylesheet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CssStylesheet类属于HTMLConverter命名空间,在下文中一共展示了CssStylesheet类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: ConvertHTML
public void ConvertHTML(string htmlString)
{
// string NEW_LINE = Environment.NewLine;
//htmlString.Replace()
htmlMain = HtmlParser.ParseHtml(htmlString);
CssStylesheet stylesheet = new CssStylesheet(htmlMain);
// Source context is a stack of all elements - ancestors of a parentElement
List<XmlElement> sourceContext = new List<XmlElement>(10);
Block b = AddBlock(htmlMain, new Hashtable(), stylesheet);
if(b is Section)
{
master = (Section)b;
}
master = new Section();
master.Blocks.Add(b);
}
开发者ID:alexiej,项目名称:YATE,代码行数:20,代码来源:HTMLToFlowConverter.cs
示例2: ConvertHtmlToXaml
// ---------------------------------------------------------------------
//
// Internal Methods
//
// ---------------------------------------------------------------------
#region Internal Methods
/// <summary>
/// Converts an html string into xaml string.
/// </summary>
/// <param name="htmlString">
/// Input html which may be badly formated xml.
/// </param>
/// <param name="asFlowDocument">
/// 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.
/// </param>
/// <returns>
/// Well-formed xml representing XAML equivalent for the input html string.
/// </returns>
public static string ConvertHtmlToXaml(string htmlString, bool asFlowDocument)
{
// Create well-formed Xml from Html string
XmlElement htmlElement = HtmlParser.ParseHtml(htmlString);
// Decide what name to use as a root
string rootElementName = asFlowDocument ? HtmlToXamlConverter.Xaml_FlowDocument : HtmlToXamlConverter.Xaml_Section;
// Create an XmlDocument for generated xaml
XmlDocument xamlTree = new XmlDocument();
XmlElement xamlFlowDocumentElement = xamlTree.CreateElement(null, rootElementName, _xamlNamespace);
// Extract style definitions from all STYLE elements in the document
CssStylesheet stylesheet = new CssStylesheet(htmlElement);
// Source context is a stack of all elements - ancestors of a parentElement
List<XmlElement> sourceContext = new List<XmlElement>(10);
// Clear fragment parent
InlineFragmentParentElement = null;
// convert root html element
AddBlock(xamlFlowDocumentElement, htmlElement, new Hashtable(), stylesheet, sourceContext);
// In case if the selected fragment is inline, extract it into a separate Span wrapper
if (!asFlowDocument)
{
xamlFlowDocumentElement = ExtractInlineFragment(xamlFlowDocumentElement);
}
// Return a string representing resulting Xaml
xamlFlowDocumentElement.SetAttribute("xml:space", "preserve");
string xaml = xamlFlowDocumentElement.OuterXml;
return xaml;
}
开发者ID:AntonioJorgeFlorindo,项目名称:StarterKits,代码行数:58,代码来源:HtmlToXamlConverter.cs
示例3: AddDataToTableCell
/// <summary>
/// adds table cell data to xamlTableCellElement
/// </summary>
/// <param name="xamlTableCellElement">
/// XmlElement representing Xaml TableCell element to which the converted data should be added
/// </param>
/// <param name="htmlDataStartNode">
/// XmlElement representing the start element of data to be added to xamlTableCellElement
/// </param>
/// <param name="currentProperties">
/// Current properties for the html td/th element corresponding to xamlTableCellElement
/// </param>
private void AddDataToTableCell(TableCell tc, XmlNode htmlDataStartNode, Hashtable currentProperties, CssStylesheet stylesheet)
{
// Parameter validation
Debug.Assert(currentProperties != null);
for (XmlNode htmlChildNode = htmlDataStartNode; htmlChildNode != null; htmlChildNode = htmlChildNode != null ? htmlChildNode.NextSibling : null)
{
// Process a new html element and add it to the td element
Block b = AddBlock(htmlChildNode, currentProperties, stylesheet);
if (b != null)
{
tc.Blocks.Add(b);
}
}
}
开发者ID:alexiej,项目名称:YATE,代码行数:27,代码来源:HTMLToFlowConverter.table.cs
示例4: AddSpanOrRun
private static void AddSpanOrRun(XmlElement xamlParentElement, XmlElement htmlElement, Hashtable inheritedProperties, CssStylesheet stylesheet, List<XmlElement> sourceContext)
{
// Decide what XAML element to use for this inline element.
// Check whether it contains any nested inlines
bool elementHasChildren = false;
for (XmlNode htmlNode = htmlElement.FirstChild; htmlNode != null; htmlNode = htmlNode.NextSibling)
{
if (htmlNode is XmlElement)
{
string htmlChildName = ((XmlElement)htmlNode).LocalName.ToLower();
if (HtmlSchema.IsInlineElement(htmlChildName) || HtmlSchema.IsBlockElement(htmlChildName) ||
htmlChildName == "img" || htmlChildName == "br" || htmlChildName == "hr")
{
elementHasChildren = true;
break;
}
}
}
string xamlElementName = elementHasChildren ? HtmlToXamlConverter.Xaml_Span : HtmlToXamlConverter.Xaml_Run;
// Create currentProperties as a compilation of local and inheritedProperties, set localProperties
Hashtable localProperties;
Hashtable currentProperties = GetElementProperties(htmlElement, inheritedProperties, out localProperties, stylesheet, sourceContext);
// Create a XAML element corresponding to this html element
XmlElement xamlElement = xamlParentElement.OwnerDocument.CreateElement(/*prefix:*/null, /*localName:*/xamlElementName, _xamlNamespace);
ApplyLocalProperties(xamlElement, localProperties, /*isBlock:*/false);
// Recurse into element subtree
for (XmlNode htmlChildNode = htmlElement.FirstChild; htmlChildNode != null; htmlChildNode = htmlChildNode.NextSibling)
{
AddInline(xamlElement, htmlChildNode, currentProperties, stylesheet, sourceContext);
}
// Add the new element to the parent.
xamlParentElement.AppendChild(xamlElement);
}
开发者ID:GAMP,项目名称:DataInterfaces,代码行数:38,代码来源:htmltoxamlconverter.cs
示例5: AddParagraph
/// <summary>
/// Generates Paragraph element from P, H1-H7, Center etc.
/// </summary>
/// <param name="xamlParentElement">
/// XmlElement representing Xaml parent to which the converted element should be added
/// </param>
/// <param name="htmlElement">
/// XmlElement representing Html element to be converted
/// </param>
/// <param name="inheritedProperties">
/// properties inherited from parent context
/// </param>
/// <param name="stylesheet"></param>
/// <param name="sourceContext"></param>
/// true indicates that a content added by this call contains at least one block element
/// </param>
private static void AddParagraph(XmlElement xamlParentElement, XmlElement htmlElement, Hashtable inheritedProperties, CssStylesheet stylesheet, List<XmlElement> sourceContext)
{
// Create currentProperties as a compilation of local and inheritedProperties, set localProperties
Hashtable localProperties;
Hashtable currentProperties = GetElementProperties(htmlElement, inheritedProperties, out localProperties, stylesheet, sourceContext);
// Create a XAML element corresponding to this html element
XmlElement xamlElement = xamlParentElement.OwnerDocument.CreateElement(/*prefix:*/null, /*localName:*/HtmlToXamlConverter.Xaml_Paragraph, _xamlNamespace);
ApplyLocalProperties(xamlElement, localProperties, /*isBlock:*/true);
// Recurse into element subtree
for (XmlNode htmlChildNode = htmlElement.FirstChild; htmlChildNode != null; htmlChildNode = htmlChildNode.NextSibling)
{
AddInline(xamlElement, htmlChildNode, currentProperties, stylesheet, sourceContext);
}
// Add the new element to the parent.
xamlParentElement.AppendChild(xamlElement);
}
开发者ID:GAMP,项目名称:DataInterfaces,代码行数:35,代码来源:htmltoxamlconverter.cs
示例6: AddListItem
/// <summary>
/// Converts htmlLIElement into Xaml ListItem element, and appends it to the parent xamlListElement
/// </summary>
/// <param name="xamlListElement">
/// XmlElement representing Xaml List element to which the converted td/th should be added
/// </param>
/// <param name="htmlLIElement">
/// XmlElement representing Html li element to be converted
/// </param>
/// <param name="inheritedProperties">
/// Properties inherited from parent context
/// </param>
private static void AddListItem(XmlElement xamlListElement, XmlElement htmlLIElement, Hashtable inheritedProperties, CssStylesheet stylesheet, List<XmlElement> sourceContext)
{
// Parameter validation
Debug.Assert(xamlListElement != null);
Debug.Assert(xamlListElement.LocalName == Xaml_List);
Debug.Assert(htmlLIElement != null);
Debug.Assert(htmlLIElement.LocalName.ToLower() == "li");
Debug.Assert(inheritedProperties != null);
Hashtable localProperties;
Hashtable currentProperties = GetElementProperties(htmlLIElement, inheritedProperties, out localProperties, stylesheet, sourceContext);
XmlElement xamlListItemElement = xamlListElement.OwnerDocument.CreateElement(null, Xaml_ListItem, _xamlNamespace);
// TODO: process local properties for li element
// Process children of the ListItem
for (XmlNode htmlChildNode = htmlLIElement.FirstChild; htmlChildNode != null; htmlChildNode = htmlChildNode != null ? htmlChildNode.NextSibling : null)
{
htmlChildNode = AddBlock(xamlListItemElement, htmlChildNode, currentProperties, stylesheet, sourceContext);
}
// Add resulting ListBoxItem to a xaml parent
xamlListElement.AppendChild(xamlListItemElement);
}
开发者ID:GAMP,项目名称:DataInterfaces,代码行数:37,代码来源:htmltoxamlconverter.cs
示例7: AddInline
// .............................................................
//
// Inline Elements
//
// .............................................................
private static void AddInline(XmlElement xamlParentElement, XmlNode htmlNode, Hashtable inheritedProperties, CssStylesheet stylesheet, List<XmlElement> sourceContext)
{
if (htmlNode is XmlComment)
{
DefineInlineFragmentParent((XmlComment)htmlNode, xamlParentElement);
}
else if (htmlNode is XmlText)
{
AddTextRun(xamlParentElement, htmlNode.Value);
}
else if (htmlNode is XmlElement)
{
XmlElement htmlElement = (XmlElement)htmlNode;
// Check whether this is an html element
if (htmlElement.NamespaceURI != HtmlParser.XhtmlNamespace)
{
return; // Skip non-html elements
}
// Identify element name
string htmlElementName = htmlElement.LocalName.ToLower();
// Put source element to the stack
sourceContext.Add(htmlElement);
switch (htmlElementName)
{
case "a":
AddHyperlink(xamlParentElement, htmlElement, inheritedProperties, stylesheet, sourceContext);
break;
case "img":
AddImage(xamlParentElement, htmlElement, inheritedProperties, stylesheet, sourceContext);
break;
case "br":
case "hr":
AddBreak(xamlParentElement, htmlElementName);
break;
default:
if (HtmlSchema.IsInlineElement(htmlElementName) || HtmlSchema.IsBlockElement(htmlElementName))
{
// Note: actually we do not expect block elements here,
// but if it happens to be here, we will treat it as a Span.
AddSpanOrRun(xamlParentElement, htmlElement, inheritedProperties, stylesheet, sourceContext);
}
break;
}
// Ignore all other elements non-(block/inline/image)
// Remove the element from the stack
Debug.Assert(sourceContext.Count > 0 && sourceContext[sourceContext.Count - 1] == htmlElement);
sourceContext.RemoveAt(sourceContext.Count - 1);
}
}
开发者ID:GAMP,项目名称:DataInterfaces,代码行数:60,代码来源:htmltoxamlconverter.cs
示例8: AddImage
// .............................................................
//
// Images
//
// .............................................................
private static void AddImage(XmlElement xamlParentElement, XmlElement htmlElement, Hashtable inheritedProperties, CssStylesheet stylesheet, List<XmlElement> sourceContext)
{
string href = GetAttribute(htmlElement, "src");
if (href == null)
{
// When href attribute is missing - ignore the hyperlink
AddSpanOrRun(xamlParentElement, htmlElement, inheritedProperties, stylesheet, sourceContext);
}
else
{
// Create currentProperties as a compilation of local and inheritedProperties, set localProperties
Hashtable localProperties;
Hashtable currentProperties = GetElementProperties(htmlElement, inheritedProperties, out localProperties, stylesheet, sourceContext);
// Create a XAML element corresponding to this html element
XmlElement xamlElement = xamlParentElement.OwnerDocument.CreateElement(/*prefix:*/null, /*localName:*/"Image", _xamlNamespace);
ApplyLocalProperties(xamlElement, localProperties, /*isBlock:*/false);
string[] hrefParts = href.Split(new char[] { '#' });
if (hrefParts.Length > 0 && hrefParts[0].Trim().Length > 0)
{
xamlElement.SetAttribute("Source", hrefParts[0].Trim());
xamlElement.SetAttribute("Stretch", "None");
}
// Recurse into element subtree
for (XmlNode htmlChildNode = htmlElement.FirstChild; htmlChildNode != null; htmlChildNode = htmlChildNode.NextSibling)
{
AddInline(xamlElement, htmlChildNode, currentProperties, stylesheet, sourceContext);
}
// Add the new element to the parent.
xamlParentElement.AppendChild(xamlElement);
}
}
开发者ID:GAMP,项目名称:DataInterfaces,代码行数:40,代码来源:htmltoxamlconverter.cs
示例9: AddColumnInformation
/// <summary>
/// Processes the information about table columns - COLGROUP and COL html elements.
/// </summary>
/// <param name="htmlTableElement">
/// XmlElement representing a source html table.
/// </param>
/// <param name="xamlTableElement">
/// XmlElement repesenting a resulting xaml table.
/// </param>
/// <param name="columnStartsAllRows">
/// Array of doubles - column start coordinates.
/// Can be null, which means that column size information is not available
/// and we must use source colgroup/col information.
/// In case wneh it's not null, we will ignore source colgroup/col information.
/// </param>
/// <param name="currentProperties"></param>
/// <param name="stylesheet"></param>
/// <param name="sourceContext"></param>
private static void AddColumnInformation(XmlElement htmlTableElement, XmlElement xamlTableElement, ArrayList columnStartsAllRows, Hashtable currentProperties, CssStylesheet stylesheet, List<XmlElement> sourceContext)
{
// Add column information
if (columnStartsAllRows != null)
{
// We have consistent information derived from table cells; use it
// The last element in columnStarts represents the end of the table
for (int columnIndex = 0; columnIndex < columnStartsAllRows.Count - 1; columnIndex++)
{
XmlElement xamlColumnElement;
xamlColumnElement = xamlTableElement.OwnerDocument.CreateElement(null, Xaml_TableColumn, _xamlNamespace);
xamlColumnElement.SetAttribute(Xaml_Width, ((double)columnStartsAllRows[columnIndex + 1] - (double)columnStartsAllRows[columnIndex]).ToString());
xamlTableElement.AppendChild(xamlColumnElement);
}
}
else
{
// We do not have consistent information from table cells;
// Translate blindly colgroups from html.
for (XmlNode htmlChildNode = htmlTableElement.FirstChild; htmlChildNode != null; htmlChildNode = htmlChildNode.NextSibling)
{
if (htmlChildNode.LocalName.ToLower() == "colgroup")
{
// TODO: add column width information to this function as a parameter and process it
AddTableColumnGroup(xamlTableElement, (XmlElement)htmlChildNode, currentProperties, stylesheet, sourceContext);
}
else if (htmlChildNode.LocalName.ToLower() == "col")
{
AddTableColumn(xamlTableElement, (XmlElement)htmlChildNode, currentProperties, stylesheet, sourceContext);
}
else if (htmlChildNode is XmlElement)
{
// Some element which belongs to table body. Stop column loop.
break;
}
}
}
}
开发者ID:GAMP,项目名称:DataInterfaces,代码行数:57,代码来源:htmltoxamlconverter.cs
示例10: AddImage
private static void AddImage(XmlElement xamlParentElement, XmlElement htmlElement, Hashtable inheritedProperties, CssStylesheet stylesheet, List<XmlElement> sourceContext)
{
// Create currentProperties as a compilation of local and inheritedProperties, set localProperties
Hashtable localProperties;
Hashtable currentProperties = GetElementProperties(htmlElement, inheritedProperties, out localProperties, stylesheet, sourceContext);
// Create a XAML element corresponding to this html element
XmlElement xamlElement = xamlParentElement.OwnerDocument.CreateElement(/*prefix:*/null, /*localName:*/HtmlToXamlConverter.Xaml_Image, _xamlNamespace);
ApplyLocalProperties(xamlElement, localProperties, /*isBlock:*/false);
if (!xamlElement.HasAttribute(Xaml_MaxHeight) && !xamlElement.HasAttribute(Xaml_MaxWidth))
{
xamlElement.SetAttribute("Stretch", BlockContainers.Contains(xamlParentElement.Name) ? "UniformToFill" : "None");
}
XmlElement container = xamlParentElement.OwnerDocument.CreateElement(
null,
BlockContainers.Contains(xamlParentElement.Name) ? "BlockUIContainer" : "InlineUIContainer",
_xamlNamespace);
container.AppendChild(xamlElement);
xamlParentElement.AppendChild(container);
}
开发者ID:QingWei-Li,项目名称:MyLife,代码行数:23,代码来源:HtmlToXamlConverter.cs
示例11: AddImage
// .............................................................
//
// Images
//
// .............................................................
private static void AddImage(XmlElement xamlParentElement, XmlElement htmlElement, Hashtable inheritedProperties, CssStylesheet stylesheet, List<XmlElement> sourceContext)
{
// Implement images
}
开发者ID:AntonioJorgeFlorindo,项目名称:StarterKits,代码行数:10,代码来源:HtmlToXamlConverter.cs
示例12: GetElementPropertiesFromCssAttributes
// .................................................................
//
// Processing CSS Attributes
//
// .................................................................
internal static void GetElementPropertiesFromCssAttributes(XmlElement htmlElement, string elementName, CssStylesheet stylesheet, Hashtable localProperties, List<XmlElement> sourceContext)
{
string styleFromStylesheet = stylesheet.GetStyle(elementName, sourceContext);
string styleInline = HtmlToXamlConverter.GetAttribute(htmlElement, "style");
// Combine styles from stylesheet and from inline attribute.
// The order is important - the latter styles will override the former.
string style = styleFromStylesheet != null ? styleFromStylesheet : null;
if (styleInline != null)
{
style = style == null ? styleInline : (style + ";" + styleInline);
}
// Apply local style to current formatting properties
if (style != null)
{
string[] styleValues = style.Split(';');
for (int i = 0; i < styleValues.Length; i++)
{
string[] styleNameValue;
styleNameValue = styleValues[i].Split(':');
if (styleNameValue.Length == 2)
{
string styleName = styleNameValue[0].Trim().ToLower();
string styleValue = HtmlToXamlConverter.UnQuote(styleNameValue[1].Trim()).ToLower();
int nextIndex = 0;
switch (styleName)
{
case "font":
// ParseCssFont(styleValue, localProperties);
break;
case "font-family":
// ParseCssFontFamily(styleValue, ref nextIndex, localProperties);
break;
case "font-size":
// ParseCssSize(styleValue, ref nextIndex, localProperties, "font-size", /*mustBeNonNegative:*/true);
break;
case "font-style":
ParseCssFontStyle(styleValue, ref nextIndex, localProperties);
break;
case "font-weight":
ParseCssFontWeight(styleValue, ref nextIndex, localProperties);
break;
case "font-variant":
ParseCssFontVariant(styleValue, ref nextIndex, localProperties);
break;
case "line-height":
// ParseCssSize(styleValue, ref nextIndex, localProperties, "line-height", /*mustBeNonNegative:*/true);
break;
case "word-spacing":
// Implement word-spacing conversion
break;
case "letter-spacing":
// Implement letter-spacing conversion
break;
case "color":
// ParseCssColor(styleValue, ref nextIndex, localProperties, "color");
break;
case "text-decoration":
ParseCssTextDecoration(styleValue, ref nextIndex, localProperties);
break;
case "text-transform":
ParseCssTextTransform(styleValue, ref nextIndex, localProperties);
break;
case "background-color":
ParseCssColor(styleValue, ref nextIndex, localProperties, "background-color");
break;
case "background":
// TODO: need to parse composite background property
ParseCssBackground(styleValue, ref nextIndex, localProperties);
break;
case "text-align":
ParseCssTextAlign(styleValue, ref nextIndex, localProperties);
break;
case "vertical-align":
ParseCssVerticalAlign(styleValue, ref nextIndex, localProperties);
break;
case "text-indent":
ParseCssSize(styleValue, ref nextIndex, localProperties, "text-indent", /*mustBeNonNegative:*/false);
break;
case "width":
case "height":
ParseCssSize(styleValue, ref nextIndex, localProperties, styleName, /*mustBeNonNegative:*/true);
break;
case "margin": // top/right/bottom/left
//.........这里部分代码省略.........
开发者ID:QingWei-Li,项目名称:MyLife,代码行数:101,代码来源:HtmlCssParser.cs
示例13: AddTableColumn
/// <summary>
/// Converts htmlColElement into Xaml TableColumn element, and appends it to the parent
/// xamlTableColumnGroupElement
/// </summary>
/// <param name="xamlTableElement"></param>
/// <param name="htmlColElement">
/// XmlElement representing Html col element to be converted
/// </param>
/// <param name="inheritedProperties">
/// properties inherited from parent context
/// </param>
/// <param name="stylesheet"></param>
/// <param name="sourceContext"></param>
private void AddTableColumn(Table table, XmlElement htmlColElement, Hashtable inheritedProperties, CssStylesheet stylesheet)
{
//Hashtable currentProperties = new Hashtable();
// GetElementProperties((XmlElement)htmlColElement, inheritedProperties, currentProperties, stylesheet);
TableColumn tcol = new TableColumn();
// ApplyLocalProperties(tcol, currentProperties,/*isBlock*/true);
// TODO: process local properties for TableColumn element
// Col is an empty element, with no subtree
// xamlTableElement.AppendChild(xamlTableColumnElement);
table.Columns.Add(tcol);
}
开发者ID:alexiej,项目名称:YATE,代码行数:27,代码来源:HTMLToFlowConverter.table.cs
示例14: AddTable
private Block AddTable(XmlElement htmlElement, Hashtable inheritedProperties, CssStylesheet stylesheet)
{
try
{
Hashtable localProperties = new Hashtable();
GetElementProperties(htmlElement, inheritedProperties, localProperties, stylesheet);
// Check if the table contains only one cell - we want to take only its content
XmlElement singleCell = GetCellFromSingleCellTable(htmlElement);
if (singleCell != null)
{
Table current = new Table(); maxc = 0;
ApplyLocalProperties(current, localProperties,/*isBlock*/true);
TableRowGroup trg = new TableRowGroup();
current.RowGroups.Add(trg);
// Need to push skipped table elements onto sourceContext
for (XmlNode htmlChildNode = singleCell.FirstChild; htmlChildNode != null; htmlChildNode = htmlChildNode != null ? htmlChildNode.NextSibling : null)
{
Block b = AddBlock(htmlChildNode, localProperties, stylesheet);
if (b != null)
{
TableRow tr = new TableRow();
tr.Cells.Add(new TableCell(b));
}
}
return current;
}
else
{
Table current = new Table(); maxc = 0;
ApplyLocalProperties(current, localProperties,/*isBlock*/true);
// Analyze table structure for column widths and rowspan attributes
ArrayList columnStarts = AnalyzeTableStructure(htmlElement, stylesheet);
// Process COLGROUP & COL elements
AddColumnInformation(current, htmlElement, columnStarts, localProperties, stylesheet);
// Process table body - TBODY and TR elements
XmlNode htmlChildNode = htmlElement.FirstChild;
while (htmlChildNode != null)
{
string htmlChildName = htmlChildNode.LocalName.ToLower();
// Process the element
if (htmlChildName == "tbody" || htmlChildName == "thead" || htmlChildName == "tfoot")
{
TableRowGroup trg = new TableRowGroup();
// Add more special processing for TableHeader and TableFooter
//XmlElement xamlTableBodyElement = xamlTableElement.OwnerDocument.CreateElement(null, Xaml_TableRowGroup, _xamlNamespace);
//xamlTableElement.AppendChild(xamlTableBodyElement);
sourceContext.Add((XmlElement)htmlChildNode);
// Get properties of Html tbody element
Hashtable childProperties = new Hashtable();
GetElementProperties(htmlElement, localProperties, childProperties, stylesheet);
ApplyLocalProperties(trg, childProperties,/*isBlock*/true);
// Process children of htmlChildNode, which is tbody, for tr elements
AddTableRowsToTableBody(trg, htmlChildNode.FirstChild, childProperties, columnStarts, stylesheet);
if (trg.Rows.Count > 0)
{
current.RowGroups.Add(trg);
}
//if (xamlTableBodyElement.HasChildNodes)
//{
// xamlTableElement.AppendChild(xamlTableBodyElement);
// // else: if there is no TRs in this TBody, we simply ignore it
//}
//Debug.Assert(sourceContext.Count > 0 && sourceContext[sourceContext.Count - 1] == htmlChildNode);
sourceContext.RemoveAt(sourceContext.Count - 1);
htmlChildNode = htmlChildNode.NextSibling;
}
else if (htmlChildName == "tr")
{
// Tbody is not present, but tr element is present. Tr is wrapped in tbody
//XmlElement xamlTableBodyElement = xamlTableElement.OwnerDocument.CreateElement(null, Xaml_TableRowGroup, _xamlNamespace);
TableRowGroup trg = new TableRowGroup();
// We use currentProperties of xamlTableElement when adding rows since the tbody element is artificially created and has
// no properties of its own
htmlChildNode = AddTableRowsToTableBody(trg, htmlChildNode, localProperties, columnStarts, stylesheet);
if (trg.Rows.Count > 0)
{
current.RowGroups.Add(trg);
}
//.........这里部分代码省略.........
开发者ID:alexiej,项目名称:YATE,代码行数:101,代码来源:HTMLToFlowConverter.table.cs
示例15: AddTableColumnGroup
/// <summary>
/// Converts htmlColgroupElement into Xaml TableColumnGroup element, and appends it to the parent
/// xamlTableElement
/// </summary>
/// <param name="xamlTableElement">
/// XmlElement representing Xaml Table element to which the converted column group should be added
/// </param>
/// <param name="htmlColgroupElement">
/// XmlElement representing Html colgroup element to be converted
/// <param name="inheritedProperties">
/// Properties inherited from parent context
/// </param>
private void AddTableColumnGroup(Table table, XmlElement htmlColgroupElement, Hashtable inheritedProperties, CssStylesheet stylesheet)
{
Hashtable currentProperties = new Hashtable();
GetElementProperties((XmlElement)htmlColgroupElement, inheritedProperties, currentProperties, stylesheet);
// TODO: process local properties for colgroup
// Process children of colgroup. Colgroup may contain only col elements.
for (XmlNode htmlNode = htmlColgroupElement.FirstChild; htmlNode != null; htmlNode = htmlNode.NextSibling)
{
if (htmlNode is XmlElement && htmlNode.LocalName.ToLower() == "col")
{
AddTableColumn(table, (XmlElement)htmlNode, currentProperties, stylesheet);
}
}
}
开发者ID:alexiej,项目名称:YATE,代码行数:27,代码来源:HTMLToFlowConverter.table.cs
示例16: AddBlock
/// <summary>
/// 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).
/// </summary>
/// <param name="xamlParentElement">
/// Parent xaml element, to which new converted element will be added
/// </param>
/// <param name="htmlElement">
/// Source html element subject to convert to xaml.
/// </param>
/// <param name="inheritedProperties">
/// Properties inherited from an outer context.
/// </param>
/// <param name="stylesheet"></param>
/// <param name="sourceContext"></param>
/// <returns>
/// Last processed html node. Normally it should be the same htmlElement
/// as was passed as a paramater, but in some irregular cases
/// it could one of its following siblings.
/// The caller must use this node to get to next sibling from it.
/// </returns>
private static XmlNode AddBlock(XmlElement xamlParentElement, XmlNode htmlNode, Hashtable inheritedProperties, CssStylesheet stylesheet, List<XmlElement> sourceContext)
{
if (htmlNode is XmlComment)
{
DefineInlineFragmentParent((XmlComment)htmlNode, /*xamlParentElement:*/null);
}
else if (htmlNode is XmlText)
{
htmlNode = AddImplicitParagraph(xamlParentElement, htmlNode, inheritedProperties, stylesheet, sourceContext);
}
else if (htmlNode is XmlElement)
{
// Identify element name
XmlElement htmlElement = (XmlElement)htmlNode;
string htmlElementName = htmlElement.LocalName; // Keep the name case-sensitive to check xml names
string htmlElementNamespace = htmlElement.NamespaceURI;
if (htmlElementNamespace != HtmlParser.XhtmlNamespace)
{
// Non-html element. skip it
// Isn't it too agressive? What if this is just an error in html tag name?
// TODO: Consider skipping just a wparrer in recursing into the element tree,
// which may produce some garbage though coming from xml fragments.
return htmlElement;
}
// Put source element to the stack
sourceContext.Add(htmlElement);
// Convert the name to lowercase, because html elements are case-insensitive
htmlElementName = htmlElementName.ToLower();
// Switch to an appropriate kind of processing depending on html element name
switch (htmlElementName)
{
// Sections:
case "html":
case "body":
case "div":
case "form": // not a block according to xhtml spec
case "pre": // Renders text in a fixed-width font
case "blockquote":
case "caption":
case "center":
case "cite":
AddSection(xamlParentElement, htmlElement, inheritedProperties, stylesheet, sourceContext);
break;
// Paragraphs:
case "p":
case "h1":
case "h2":
case "h3":
case "h4":
case "h5":
case "h6":
case "nsrtitle":
case "textarea":
case "dd": // ???
case "dl": // ???
case "dt": // ???
case "tt": // ???
AddParagraph(xamlParentElement, htmlElement, inheritedProperties, stylesheet, sourceContext);
break;
case "ol":
case "ul":
case "dir": // treat as UL element
case "menu": // treat as UL element
// List element conversion
AddList(xamlParentElement, htmlElement, inheritedProperties, stylesheet, sourceContext);
//.........这里部分代码省略.........
开发者ID:GAMP,项目名称:DataInterfaces,代码行数:101,代码来源:htmltoxamlconverter.cs
示例17: GetElementProperties
/// <summary>
/// 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.
/// </sum
|
请发表评论