static TagConverter() { TagConverter document = new Document(); TagConverter paragraph = new Paragraph(); TagConverter span = new Span(); TagConverter blod = new Blod(); TagConverter linkbreak = new LineBreak(); TagConverter underline = new UnderLine(); TagConverter hyperlink = new Hyperlink(); TagConverter list = new List(); TagConverter listitem = new ListItem(); TagConverter table = new Table(); TagConverter tablerow = new TableRow(); TagConverter tablecell = new TableCell(); TagConverter run = new Run(); #region FlowDoc to Html // Flow attribute tag converter TagAttributeConverter textDecorations = new TextDecorations(); TagValueConverter textDecoration = new TextDecoration(); TagAttributeConverter margin = new Margin(); TagValueConverter thickness = new Thickness(); // Init flow tag mapping RegisterFlowToHtmlTagConverter(Tags.FLOW_FLOW_DOCUMENT, document); RegisterFlowToHtmlTagConverter(Tags.FLOW_PARAGRAPH, paragraph); RegisterFlowToHtmlTagConverter(Tags.FLOW_SPAN, span); RegisterFlowToHtmlTagConverter(Tags.FLOW_RUN, run); RegisterFlowToHtmlTagConverter(Tags.FLOW_BLOD, blod); RegisterFlowToHtmlTagConverter(Tags.FLOW_LINE_BREAK, linkbreak); RegisterFlowToHtmlTagConverter(Tags.FLOW_UNDER_LINE, underline); RegisterFlowToHtmlTagConverter(Tags.FLOW_HYPER_LINK, hyperlink); RegisterFlowToHtmlTagConverter(Tags.FLOW_LIST, list); RegisterFlowToHtmlTagConverter(Tags.FLOW_LIST_ITEM, listitem); // Table / TableRow / TableCell RegisterFlowToHtmlTagConverter(Tags.FLOW_TABLE, table); RegisterFlowToHtmlTagConverter(Tags.FLOW_TABLE_ROW, tablerow); RegisterFlowToHtmlTagConverter(Tags.FLOW_TABLE_CELL, tablecell); // TextDecorations / TextDecoration RegisterFlowToHtmlTagConverter(Attributes.FLOW_TAG_TEXT_DECORATIONS, textDecorations); RegisterFlowToHtmlTagConverter(Tags.FLOW_TEXT_DECORATION, textDecoration); // Margin / Thickness RegisterFlowToHtmlTagConverter(Attributes.FLOW_TAG_MARGIN, margin); RegisterFlowToHtmlTagConverter(Tags.FLOW_THICKNESS, thickness); #endregion #region Html to FlowDoc HtmlHeader header = new HtmlHeader(); RegisterHtmlToFlowTagConverter(Tags.HTML_H1, header); RegisterHtmlToFlowTagConverter(Tags.HTML_H2, header); RegisterHtmlToFlowTagConverter(Tags.HTML_H3, header); RegisterHtmlToFlowTagConverter(Tags.HTML_H4, header); RegisterHtmlToFlowTagConverter(Tags.HTML_H5, header); RegisterHtmlToFlowTagConverter(Tags.HTML_H6, header); // Init html tag mapping //RegisterHtmlToFlowTagConverter(Tags.HTML_P, paragraph); //RegisterHtmlToFlowTagConverter(Tags.HTML_SPAN, span); //RegisterHtmlToFlowTagConverter(Tags.HTML_B, blod); //RegisterHtmlToFlowTagConverter(Tags.HTML_BR, linkbreak); //RegisterHtmlToFlowTagConverter(Tags.HTML_U, underline); //RegisterHtmlToFlowTagConverter(Tags.HTML_A, hyperlink); //RegisterHtmlToFlowTagConverter(Tags.HTML_UL, list); //RegisterHtmlToFlowTagConverter(Tags.HTML_LI, listitem); //RegisterHtmlToFlowTagConverter(Tags.HTML_TABLE, table); //RegisterHtmlToFlowTagConverter(Tags.HTML_TR, tablerow); //RegisterHtmlToFlowTagConverter(Tags.HTML_TD, tablecell); #endregion }
/// <summary> /// Generate all html text that within table tag /// </summary> /// <param name="root"></param> /// <returns></returns> public override string ToHtml(XmlNode root, int sequence) { StringBuilder buffer = new StringBuilder(); StringBuilder attributeBuffer = new StringBuilder(); attributeBuffer.Append(GenHtmlAttributes(root, sequence)); foreach (XmlNode node in root.ChildNodes) { // To go to inside of TableRowGroup tag if (node.NodeType == XmlNodeType.Element) { // Table.Columns if (node.Name == Tags.FLOW_TABLE_COLUMNS) { // TableColumn int seq = 1; Dictionary<int, List<AttributeEntity>> atts = new Dictionary<int, List<AttributeEntity>>(); foreach (XmlNode columnNode in node.ChildNodes) { if (columnNode.NodeType == XmlNodeType.Element && string.Compare(columnNode.Name, Tags.FLOW_TABLE_COLUMN, false) == 0) { List<AttributeEntity> transimtAtts = new List<AttributeEntity>(columnNode.Attributes.Count); foreach (XmlAttribute att in columnNode.Attributes) transimtAtts.Add(new AttributeEntity() { Name = att.Name, Value = att.Value }); atts.Add(seq, transimtAtts); seq++; } } // Add inherit attribute, assign to TableCell tag _inheritAttributes.Add(Tags.FLOW_TABLE_CELL, atts); } // TableRowGroup else if (node.Name == Tags.FLOW_TABLE_ROW_GROUP) { int seq = 1; foreach (XmlNode rowNode in node.ChildNodes) { if (rowNode.NodeType == XmlNodeType.Element && string.Compare(rowNode.Name, Tags.FLOW_TABLE_ROW, false) == 0) { TagConverter rowConverter = GetConverterByFlowTag(rowNode.Name); // Pass parent attribute to child if (_inheritAttributes.Count > 0) rowConverter.AddRangeToInheritAttribute(_inheritAttributes); buffer.Append(rowConverter.ToHtml(rowNode, seq++)); } } } } } buffer.Insert(0, string.Format("<{0}{1}>", HTMLTag, CombianAttributes(attributeBuffer))); buffer.Append(Tags.GetXmlEndTag(_htmlTag)); return buffer.ToString(); }