internal override void Process(DocxNode node, ref Paragraph paragraph) { if (node.IsNull() || node.Parent == null || !CanConvert(node) || IsHidden(node)) { return; } paragraph = null; if (node.HasChildren) { Table table = new Table(); DocxTableProperties tableProperties = new DocxTableProperties(); tableProperties.FetchTableProperties(node); tableProperties.ApplyTableProperties(table, node); foreach (DocxNode child in node.Children) { if (string.Compare(child.Tag, DocxTableProperties.trName, StringComparison.InvariantCultureIgnoreCase) == 0) { node.CopyExtentedStyles(child); ProcessTr(child, table, tableProperties); } else if (tableProperties.IsGroupElement(child.Tag)) { node.CopyExtentedStyles(child); ProcessGroupElement(child, table, tableProperties); } } node.Parent.Append(table); } }
private void ProcessNonLinkText(DocxNode node, ref Paragraph paragraph) { foreach (DocxNode child in node.Children) { if (child.IsText) { if (paragraph == null) { paragraph = node.Parent.AppendChild(new Paragraph()); OnParagraphCreated(node.ParagraphNode, paragraph); } if (!IsEmptyText(child.InnerHtml)) { Run run = paragraph.AppendChild<Run>(new Run(new Text() { Text = ClearHtml(child.InnerHtml), Space = SpaceProcessingModeValues.Preserve })); RunCreated(node, run); } } else { child.ParagraphNode = node.ParagraphNode; child.Parent = node.Parent; node.CopyExtentedStyles(child); ProcessChild(child, ref paragraph); } } }
internal override void Process(DocxNode node, ref Paragraph paragraph) { if (node.IsNull() || !CanConvert(node) || IsHidden(node)) { return; } paragraph = null; if (node.HasChildren) { numberFormat = GetNumberFormat(node); InitNumberDefinitions(numberFormat); foreach (DocxNode child in node.Children) { if (string.Compare(child.Tag, liName, StringComparison.InvariantCultureIgnoreCase) == 0) { node.CopyExtentedStyles(child); ProcessLi(child, node.Parent, numberFormat); } } } }
internal override void Process(DocxNode node, ref Paragraph paragraph, Dictionary <string, object> properties) { if (node.IsNull() || !CanConvert(node) || IsHidden(node)) { return; } paragraph = null; int levelIndex = properties.ContainsKey(levelIndexName) ? Convert.ToInt32(properties[levelIndexName]) : 0; if (node.HasChildren) { short numberId = gNumberId = ++context.ListNumberId; InitNumberDefinitions(levelIndex); var newProperties = properties.ToDictionary(x => x.Key, x => x.Value); newProperties[levelIndexName] = levelIndex + 1; foreach (DocxNode child in node.Children) { //Dirty hack to maintain the level since these elements are singleton. When it traverse to inner html elements, the level will increment //then, when it goes back to more root elements, we have to reset the level to its previous state. gLevelIndex = levelIndex; gNumberId = numberId; if (string.Compare(child.Tag, liName, StringComparison.InvariantCultureIgnoreCase) == 0) { node.CopyExtentedStyles(child); ProcessLi(child, node.Parent, newProperties); } } } }
private void ProcessChild(DocxNode node, Dictionary <string, object> properties) { if (node.IsNull()) { return; } Paragraph paragraph = node.Parent.AppendChild(new Paragraph()); OnParagraphCreated(node, paragraph); foreach (DocxNode child in node.Children) { if (child.IsText && !IsEmptyText(child.InnerHtml)) { Run run = paragraph.AppendChild(new Run(new Text() { Text = ClearHtml(child.InnerHtml), Space = SpaceProcessingModeValues.Preserve })); RunCreated(node, run); } else { child.ParagraphNode = node; child.Parent = node.Parent; node.CopyExtentedStyles(child); ProcessChild(child, ref paragraph, properties); } } }
private void ProcessNonLinkText(DocxNode node, ref Paragraph paragraph) { foreach (DocxNode child in node.Children) { if (child.IsText) { if (paragraph == null) { paragraph = node.Parent.AppendChild(new Paragraph()); OnParagraphCreated(node.ParagraphNode, paragraph); } if (!IsEmptyText(child.InnerHtml)) { Run run = paragraph.AppendChild <Run>(new Run(new Text() { Text = ClearHtml(child.InnerHtml), Space = SpaceProcessingModeValues.Preserve })); RunCreated(node, run); } } else { child.ParagraphNode = node.ParagraphNode; child.Parent = node.Parent; node.CopyExtentedStyles(child); ProcessChild(child, ref paragraph); } } }
private void ProcessTr(DocxNode tr, Table table, DocxTableProperties tableProperties) { if (tr.HasChildren) { TableRow row = new TableRow(); DocxTableRowStyle style = new DocxTableRowStyle(); style.Process(row, tableProperties); int colIndex = 0; foreach (DocxNode td in tr.Children) { ProcessVerticalSpan(ref colIndex, row, tableProperties); tableProperties.IsCellHeader = string.Compare(td.Tag, DocxTableProperties.thName, StringComparison.InvariantCultureIgnoreCase) == 0; if (string.Compare(td.Tag, DocxTableProperties.tdName, StringComparison.InvariantCultureIgnoreCase) == 0 || tableProperties.IsCellHeader) { tr.CopyExtentedStyles(td); ProcessTd(colIndex++, td, row, tableProperties); } } if (colIndex < tableProperties.RowSpanInfo.Count) { ProcessVerticalSpan(ref colIndex, row, tableProperties); } table.Append(row); } }
internal override void Process(DocxNode node, ref Paragraph paragraph) { if (node.IsNull() || IsHidden(node)) { return; } string link = node.ExtractAttributeValue(href); link = CleanUrl(link); if (Uri.IsWellFormedUriString(link, UriKind.Absolute)) { Uri uri = new Uri(link); var relationship = context.MainDocumentPart.AddHyperlinkRelationship(uri, uri.IsAbsoluteUri); var hyperLink = new Hyperlink() { History = true, Id = relationship.Id }; foreach (DocxNode child in node.Children) { if (child.IsText) { if (!IsEmptyText(child.InnerHtml)) { Run run = hyperLink.AppendChild <Run>(new Run(new Text() { Text = ClearHtml(child.InnerHtml), Space = SpaceProcessingModeValues.Preserve })); run.RunProperties = new RunProperties((new RunStyle() { Val = "Hyperlink" })); RunCreated(node, run); } } else { child.Parent = hyperLink; node.CopyExtentedStyles(child); ProcessTextElement(child); } } CreateParagraph(node, ref paragraph); paragraph.Append(hyperLink); } else { ProcessNonLinkText(node, ref paragraph); } }
private void ProcessGroupElement(DocxNode tbody, Table table, DocxTableProperties tableProperties) { foreach (DocxNode tr in tbody.Children) { if (string.Compare(tr.Tag, DocxTableProperties.trName, StringComparison.InvariantCultureIgnoreCase) == 0) { tbody.CopyExtentedStyles(tr); ProcessTr(tr, table, tableProperties); } } }
internal override void Process(DocxNode node, ref Paragraph paragraph, Dictionary <string, object> properties) { if (node.IsNull() || node.Parent == null || !CanConvert(node) || IsHidden(node)) { return; } if (!node.HasChildren) { return; } paragraph = null; //Add an empty paragraph to set default margin top SetMarginTop(node.Parent); foreach (DocxNode child in node.Children) { if (string.Compare(child.Tag, "dt", StringComparison.InvariantCultureIgnoreCase) == 0) { child.Parent = node.Parent; node.CopyExtentedStyles(child); ProcessChild(child, properties); } else if (string.Compare(child.Tag, "dd", StringComparison.InvariantCultureIgnoreCase) == 0) { node.CopyExtentedStyles(child); SetDDProperties(child); child.Parent = node.Parent; ProcessChild(child, properties); } } //Add an empty paragraph at the end to set default margin bottom SetMarginBottom(node.Parent); }
protected void ProcessElement(DocxNode node, ref Paragraph paragraph, Dictionary <string, object> properties) { foreach (DocxNode child in node.Children) { if (child.IsText) { ProcessParagraph(child, node, node.ParagraphNode, ref paragraph); } else { child.ParagraphNode = node.ParagraphNode; child.Parent = node.Parent; node.CopyExtentedStyles(child); ProcessChild(child, ref paragraph, properties); } } }
protected void ProcessBlockElement(DocxNode node, ref Paragraph paragraph, Dictionary <string, object> properties) { foreach (DocxNode child in node.Children) { if (child.IsText) { ProcessParagraph(child, node, node, ref paragraph); } else { //ProcessChild forwards the incomming parent to the child element. So any div element inside this div //creates a new paragraph on the parent element. child.ParagraphNode = node; child.Parent = node.Parent; node.CopyExtentedStyles(child); ProcessChild(child, ref paragraph, properties); } } }
internal override void Process(DocxNode node, ref Paragraph paragraph) { if (node.IsNull() || node.Parent == null || IsHidden(node)) { return; } foreach (DocxNode child in node.Children) { if (child.IsText) { if (!IsEmptyText(child.InnerHtml)) { ApplyOpenQuoteIfEmpty(node, ref paragraph); Run run = paragraph.AppendChild(new Run(new Text() { Text = ClearHtml(child.InnerHtml), Space = SpaceProcessingModeValues.Preserve })); RunCreated(node, run); } } else { child.ParagraphNode = node.ParagraphNode; child.Parent = node.Parent; node.CopyExtentedStyles(child); ApplyOpenQuoteIfEmpty(node, ref paragraph); ProcessChild(child, ref paragraph); } } if (paragraph != null && hasOpenQuote) { paragraph.AppendChild(new Run(new Text() { Text = "\"" })); } }
protected void ProcessTextChild(DocxNode node) { foreach (DocxNode child in node.Children) { if (child.IsText && !IsEmptyText(child.InnerHtml)) { Run run = node.Parent.AppendChild(new Run(new Text() { Text = ClearHtml(child.InnerHtml), Space = SpaceProcessingModeValues.Preserve })); RunCreated(node, run); } else { child.Parent = node.Parent; node.CopyExtentedStyles(child); ProcessTextElement(child); } } }
private void ProcessChildren(DocxNode currentNode, DocxNode newNode, Run run) { foreach (DocxNode child in currentNode.Children) { if (child.IsText) { if (!IsEmptyText(child.InnerHtml)) { run.AppendChild(new Text() { Text = ClearHtml(child.InnerHtml), Space = SpaceProcessingModeValues.Preserve }); } } else { currentNode.CopyExtentedStyles(newNode); ProcessTextElement(newNode); } } }
internal override void Process(DocxNode node, ref Paragraph paragraph, Dictionary <string, object> properties) { if (node.IsNull() || !CanConvert(node) || IsHidden(node)) { return; } paragraph = null; int levelIndex = properties.ContainsKey(levelIndexName) ? Convert.ToInt32(properties[levelIndexName]) : 0; if (abstractNum == null) { InitNumberDefinitions(); } if (node.HasChildren) { NumberFormatValues numberFormat = GetNumberFormat(node); int levelId = gLevelId = gNextLevelId++; DefineLevel(numberFormat, levelIndex); var newProperties = properties.ToDictionary(x => x.Key, x => x.Value); newProperties[levelIndexName] = levelIndex + 1; foreach (DocxNode child in node.Children) { gLevelIndex = levelIndex; gLevelId = levelId; if (string.Compare(child.Tag, liName, StringComparison.InvariantCultureIgnoreCase) == 0) { node.CopyExtentedStyles(child); ProcessLi(child, node.Parent, newProperties); } } } }
protected void ProcessTextChild(DocxNode node, Dictionary <string, object> properties) { foreach (DocxNode child in node.Children) { if (child.IsText && !IsEmptyText(child.InnerHtml)) { Run run = node.Parent.AppendChild(new Run(new Text() { Text = ClearHtml(child.InnerHtml), Space = SpaceProcessingModeValues.Preserve })); RunCreated(node, run); } else { child.Parent = node.Parent; node.CopyExtentedStyles(child); ProcessTextElement(child, properties); } } }
private void ProcessLi(DocxNode li, OpenXmlElement parent, NumberFormatValues numberFormat) { Paragraph paragraph = null; isParagraphCreated = false; ParagraphCreated = OnOLParagraphCreated; foreach (DocxNode child in li.Children) { if (child.IsText) { if (!IsEmptyText(child.InnerHtml)) { if (paragraph == null) { paragraph = CreateParagraph(li, parent); } Run run = paragraph.AppendChild(new Run(new Text() { Text = ClearHtml(child.InnerHtml), Space = SpaceProcessingModeValues.Preserve })); RunCreated(li, run); } } else { child.ParagraphNode = li; child.Parent = parent; li.CopyExtentedStyles(child); ProcessChild(child, ref paragraph); } } }
private void ProcessTd(int colIndex, DocxNode td, TableRow row, DocxTableProperties tableProperties) { TableCell cell = new TableCell(); bool hasRowSpan = false; string rowSpan = td.ExtractAttributeValue(DocxTableProperties.rowSpan); Int32 rowSpanValue; if (Int32.TryParse(rowSpan, out rowSpanValue)) { tableProperties.RowSpanInfo[colIndex] = rowSpanValue - 1; hasRowSpan = true; } DocxTableCellStyle style = new DocxTableCellStyle(); style.HasRowSpan = hasRowSpan; style.Process(cell, tableProperties, td); if (td.HasChildren) { Paragraph para = null; //If the cell is th header, apply font-weight:bold to the text if (tableProperties.IsCellHeader) { SetThStyleToRun(td); } foreach (DocxNode child in td.Children) { td.CopyExtentedStyles(child); if (child.IsText) { if (!IsEmptyText(child.InnerHtml)) { if (para == null) { para = cell.AppendChild(new Paragraph()); OnParagraphCreated(DocxTableCellStyle.GetHtmlNodeForTableCellContent(td), para); } Run run = para.AppendChild(new Run(new Text() { Text = ClearHtml(child.InnerHtml), Space = SpaceProcessingModeValues.Preserve })); RunCreated(child, run); } } else { child.ParagraphNode = DocxTableCellStyle.GetHtmlNodeForTableCellContent(td); child.Parent = cell; td.CopyExtentedStyles(child); ProcessChild(child, ref para); } } } //The last element of the table cell must be a paragraph. var lastElement = cell.Elements().LastOrDefault(); if (lastElement == null || !(lastElement is Paragraph)) { cell.AppendChild(new Paragraph()); } row.Append(cell); }
protected void ProcessElement(DocxNode node, ref Paragraph paragraph) { foreach (DocxNode child in node.Children) { if (child.IsText) { ProcessParagraph(child, node, node.ParagraphNode, ref paragraph); } else { child.ParagraphNode = node.ParagraphNode; child.Parent = node.Parent; node.CopyExtentedStyles(child); ProcessChild(child, ref paragraph); } } }
protected void ProcessBlockElement(DocxNode node, ref Paragraph paragraph) { foreach (DocxNode child in node.Children) { if (child.IsText) { ProcessParagraph(child, node, node, ref paragraph); } else { //ProcessChild forwards the incomming parent to the child element. So any div element inside this div //creates a new paragraph on the parent element. child.ParagraphNode = node; child.Parent = node.Parent; node.CopyExtentedStyles(child); ProcessChild(child, ref paragraph); } } }
private void ProcessTBody(DocxNode tbody, Table table, DocxTableProperties tableProperties) { foreach (DocxNode tr in tbody.Children) { if (string.Compare(tr.Tag, DocxTableProperties.trName, StringComparison.InvariantCultureIgnoreCase) == 0) { tbody.CopyExtentedStyles(tr); ProcessTr(tr, table, tableProperties); } } }
internal override void Process(DocxNode node, ref Paragraph paragraph) { if (node.IsNull() || node.Parent == null || !CanConvert(node) || IsHidden(node)) { return; } paragraph = null; if (node.HasChildren) { Table table = new Table(); DocxTableProperties tableProperties = new DocxTableProperties(); tableProperties.FetchTableProperties(node); tableProperties.ApplyTableProperties(table, node); foreach (DocxNode child in node.Children) { if (string.Compare(child.Tag, DocxTableProperties.trName, StringComparison.InvariantCultureIgnoreCase) == 0) { node.CopyExtentedStyles(child); ProcessTr(child, table, tableProperties); } else if (string.Compare(child.Tag, DocxTableProperties.tbody, StringComparison.InvariantCultureIgnoreCase) == 0) { node.CopyExtentedStyles(child); ProcessTBody(child, table, tableProperties); } } node.Parent.Append(table); } }
internal override void Process(DocxNode node, ref Paragraph paragraph) { if (node.IsNull() || IsHidden(node)) { return; } string link = node.ExtractAttributeValue(href); link = CleanUrl(link); if (Uri.IsWellFormedUriString(link, UriKind.Absolute)) { Uri uri = new Uri(link); var relationship = context.MainDocumentPart.AddHyperlinkRelationship(uri, uri.IsAbsoluteUri); var hyperLink = new Hyperlink() { History = true, Id = relationship.Id }; foreach (DocxNode child in node.Children) { if (child.IsText) { if (!IsEmptyText(child.InnerHtml)) { Run run = hyperLink.AppendChild<Run>(new Run(new Text() { Text = ClearHtml(child.InnerHtml), Space = SpaceProcessingModeValues.Preserve })); run.RunProperties = new RunProperties((new RunStyle() { Val = "Hyperlink" })); RunCreated(node, run); } } else { child.Parent = hyperLink; node.CopyExtentedStyles(child); ProcessTextElement(child); } } CreateParagraph(node, ref paragraph); paragraph.Append(hyperLink); } else { ProcessNonLinkText(node, ref paragraph); } }
internal override void Process(DocxNode node, ref Paragraph paragraph) { if (node.IsNull() || node.Parent == null || !CanConvert(node) || IsHidden(node)) { return; } if (!node.HasChildren) { return; } paragraph = null; //Add an empty paragraph to set default margin top SetMarginTop(node.Parent); foreach (DocxNode child in node.Children) { if (string.Compare(child.Tag, "dt", StringComparison.InvariantCultureIgnoreCase) == 0) { child.Parent = node.Parent; node.CopyExtentedStyles(child); ProcessChild(child); } else if (string.Compare(child.Tag, "dd", StringComparison.InvariantCultureIgnoreCase) == 0) { node.CopyExtentedStyles(child); SetDDProperties(child); child.Parent = node.Parent; ProcessChild(child); } } //Add an empty paragraph at the end to set default margin bottom SetMarginBottom(node.Parent); }