-
Notifications
You must be signed in to change notification settings - Fork 16
DocumentAssembler fixes #186
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
c147f0e
49ff5c2
8e78ceb
04619f8
11d35b1
79806fa
f3f820f
db482af
5b9c408
f56266e
aa10c34
02a7167
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -654,7 +654,7 @@ private class RunReplacementInfo | |
| p.Add(new XElement(W.r, | ||
| para.Elements(W.r).Elements(W.rPr).FirstOrDefault(), | ||
| (p.Elements().Count() > 1) ? new XElement(W.br) : null, | ||
| new XElement(W.t, line))); | ||
| new XElement(W.t, GetXmlSpaceAttribute(line), line))); | ||
| } | ||
| return p; | ||
| } | ||
|
|
@@ -666,7 +666,7 @@ private class RunReplacementInfo | |
| list.Add(new XElement(W.r, | ||
| run.Elements().Where(e => e.Name != W.t), | ||
| (list.Count > 0) ? new XElement(W.br) : null, | ||
| new XElement(W.t, line))); | ||
| new XElement(W.t, GetXmlSpaceAttribute(line), line))); | ||
| } | ||
| return list; | ||
| } | ||
|
|
@@ -873,9 +873,24 @@ private class RunReplacementInfo | |
| } | ||
| return null; | ||
| } | ||
| var transformedNodes = element.Nodes().Select(n => ContentReplacementTransform(n, data, templateError, owningPart)); | ||
| if (element.Name == W.tc) | ||
| { | ||
| // Check if the table cell contains any block-level elements | ||
| // Valid block-level elements in a table cell: p (paragraph), tbl (table), sdt (structured document tag), customXml | ||
| var nodesList = transformedNodes.ToList(); | ||
| var hasBlockLevelContent = nodesList.Any(n => n is XElement xe && | ||
| (xe.Name == W.p || xe.Name == W.tbl || xe.Name == W.sdt || xe.Name == W.customXml)); | ||
| if (!hasBlockLevelContent) | ||
| { | ||
| // Table cells must contain at least one block-level element -- add an empty paragraph | ||
| nodesList.Add(new XElement(W.p)); | ||
| } | ||
| transformedNodes = nodesList; | ||
| } | ||
| return new XElement(element.Name, | ||
| element.Attributes(), | ||
| element.Nodes().Select(n => ContentReplacementTransform(n, data, templateError, owningPart))); | ||
| transformedNodes); | ||
| } | ||
| return node; | ||
| } | ||
|
|
@@ -1400,5 +1415,18 @@ private static string EvaluateXPathToString(XElement element, string xPath, bool | |
|
|
||
| return xPathSelectResult.ToString(); | ||
| } | ||
|
|
||
| private static XAttribute GetXmlSpaceAttribute(string textOfTextElement) | ||
| { | ||
| if (!string.IsNullOrEmpty(textOfTextElement)) | ||
| { | ||
| if (char.IsWhiteSpace(textOfTextElement[0]) || | ||
| char.IsWhiteSpace(textOfTextElement[textOfTextElement.Length - 1])) | ||
| { | ||
| return new XAttribute(XNamespace.Xml + "space", "preserve"); | ||
| } | ||
| } | ||
| return null; | ||
| } | ||
|
Comment on lines
+1419
to
+1430
|
||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These 'if' statements can be combined.