diff --git a/Clippit.Tests/Word/DocumentAssemblerTests.cs b/Clippit.Tests/Word/DocumentAssemblerTests.cs
index 770075fc..1a9f5c88 100644
--- a/Clippit.Tests/Word/DocumentAssemblerTests.cs
+++ b/Clippit.Tests/Word/DocumentAssemblerTests.cs
@@ -179,6 +179,89 @@ out var returnedTemplateError
Assert.Equal(err, returnedTemplateError);
}
+ [Theory]
+ [InlineData("DA289-xhtml-formatting.docx", "DA289-no-inline-styles.xml", 1, false)]
+ [InlineData("DA289-xhtml-formatting.docx", "DA289-bold.xml", 1, false)]
+ [InlineData("DA289-xhtml-formatting.docx", "DA289-strong.xml", 1, false)]
+ [InlineData("DA289-xhtml-formatting.docx", "DA289-italic.xml", 1, false)]
+ [InlineData("DA289-xhtml-formatting.docx", "DA289-emphasis.xml", 1, false)]
+ [InlineData("DA289-xhtml-formatting.docx", "DA289-underline.xml", 1, false)]
+ [InlineData("DA289-xhtml-formatting.docx", "DA289-bold-underline.xml", 1, false)]
+ [InlineData("DA289-xhtml-formatting.docx", "DA289-bold-italic.xml", 1, false)]
+ [InlineData("DA289-xhtml-formatting.docx", "DA289-italic-underline.xml", 1, false)]
+ [InlineData("DA289-xhtml-formatting.docx", "DA289-subscript.xml", 1, false)]
+ [InlineData("DA289-xhtml-formatting.docx", "DA289-superscript.xml", 1, false)]
+ [InlineData("DA289-xhtml-formatting.docx", "DA289-strikethrough.xml", 1, false)]
+ [InlineData("DA289-xhtml-formatting.docx", "DA289-hyperlink.xml", 1, false)]
+ [InlineData("DA289-xhtml-formatting.docx", "DA289-hyperlink-bold.xml", 1, false)]
+ [InlineData("DA289-xhtml-formatting.docx", "DA289-hyperlink-italic.xml", 1, false)]
+ [InlineData("DA289-xhtml-formatting.docx", "DA289-hyperlink-underline.xml", 1, false)]
+ [InlineData("DA289-xhtml-formatting.docx", "DA289-hyperlink-no-protocol.xml", 1, false)]
+ [InlineData("DA289-xhtml-formatting.docx", "DA289-multi-paragraph.xml", 3, false)]
+ [InlineData("DA289-xhtml-formatting.docx", "DA289-invalid.xml", 0, true)]
+ [InlineData("DA289-xhtml-formatting.docx", "DA289-not-well-formed.xml", 0, true)]
+ public void DA289(string name, string data, int parasInContent, bool err)
+ {
+ var templateDocx = new FileInfo(Path.Combine(_sourceDir.FullName, name));
+ var dataFile = new FileInfo(Path.Combine(_sourceDir.FullName, data));
+
+ var wmlTemplate = new WmlDocument(templateDocx.FullName);
+ var xmlData = XElement.Load(dataFile.FullName);
+
+ var wmlResult = DocumentAssembler.AssembleDocument(wmlTemplate, xmlData, out var returnedTemplateError);
+ var assembledDocx = new FileInfo(
+ Path.Combine(TempDir, data.Replace(".xml", "-processed-by-DocumentAssembler.docx"))
+ );
+ wmlResult.SaveAs(assembledDocx.FullName);
+
+ Validate(assembledDocx);
+ Assert.Equal(err, returnedTemplateError);
+
+ // if we are not expecting an error then verify that we have the same number of paragraphs and that
+ // the paragraph properties from source and target are the same
+ if (!err)
+ {
+ IList sourceParas = wmlTemplate.MainDocumentPart.Element(W.body).Descendants(W.p).ToList();
+ IList targetParas = wmlResult.MainDocumentPart.Element(W.body).Descendants(W.p).ToList();
+
+ // Check we have the expected number of paragraphs
+ // Expected document structure is:
+ // Heading paragraph (1 line)
+ // Empty paragraph (1 line)
+ // Escaped HTML paragraph (potential multi-line)
+ // CDATA paragraph (potential multi-line)
+
+ int expectedParas = sourceParas.Count + (2 * parasInContent) - 2;
+ Assert.Equal(expectedParas, targetParas.Count);
+
+ var equalityComparer = new XNodeEqualityComparer();
+ int paraOffset = 0;
+
+ for (var i = 0; i < sourceParas.Count(); i++)
+ {
+ var parasToCompare = i <= 1 ? 1 : parasInContent;
+ var sourceProps = sourceParas[i].Element(W.pPr);
+
+ for (var j = i + paraOffset; j < i + paraOffset + parasToCompare; j++)
+ {
+ var targetProps = targetParas[j].Element(W.pPr);
+ if (sourceProps == null && targetProps == null)
+ {
+ continue;
+ }
+
+ Assert.True(equalityComparer.Equals(sourceProps, targetProps));
+ }
+
+ // update paragraph offset versus source when we have processed multi-line content
+ if (parasToCompare > 1)
+ {
+ paraOffset += parasToCompare - 1;
+ }
+ }
+ }
+ }
+
[Theory]
[InlineData("DA259-MultiLineContents.docx", "DA-Data.xml", false)]
public void DA259(string name, string data, bool err)
diff --git a/Clippit/PtOpenXmlUtil.cs b/Clippit/PtOpenXmlUtil.cs
index f6b08f73..9767c69e 100644
--- a/Clippit/PtOpenXmlUtil.cs
+++ b/Clippit/PtOpenXmlUtil.cs
@@ -5870,7 +5870,7 @@ public static class XhtmlNoNamespace
public static XName ol = "ol";
public static XName ul = "ul";
public static XName li = "li";
- public static XName strong = "Bold";
+ public static XName strong = "strong";
public static XName em = "em";
public static XName tbody = "tbody";
public static XName valign = "valign";
diff --git a/Clippit/Word/DocumentAssembler.cs b/Clippit/Word/DocumentAssembler.cs
index b4d4c08a..9137ab3c 100644
--- a/Clippit/Word/DocumentAssembler.cs
+++ b/Clippit/Word/DocumentAssembler.cs
@@ -1298,7 +1298,8 @@ OpenXmlPart part
return element.CreateContextErrorMessage($"Content: {ex.Message}", templateError);
}
- // get XElements and ensure all but the first element is in a
+ // get XElements and ensure all but the first element is in a paragraph
+
List elements = new List();
for (int i = 0; i < content.Count; i++)
{
@@ -1308,12 +1309,25 @@ OpenXmlPart part
var objEl = obj as XElement;
if (i > 0 && objEl.Name == W.r || objEl.Name == W.hyperlink)
{
- elements.Add(new XElement(W.p, currentParaProps, content[i]));
+ objEl = new XElement(W.p, currentParaProps, content[i]);
}
- else
+ else if (objEl.Name == W.p)
{
- elements.Add(objEl);
+ // get the processed paragraph properties
+ XElement pProps = objEl.Descendants(W.pPr).FirstOrDefault();
+ if (pProps != null)
+ {
+ pProps.Remove();
+ }
+
+ // add the current paragraph properties
+ if (currentParaProps != null)
+ {
+ objEl.AddFirst(currentParaProps);
+ }
}
+
+ elements.Add(objEl);
}
}
diff --git a/TestFiles/DA/DA289-bold-italic.xml b/TestFiles/DA/DA289-bold-italic.xml
new file mode 100644
index 00000000..a733c57f
--- /dev/null
+++ b/TestFiles/DA/DA289-bold-italic.xml
@@ -0,0 +1,5 @@
+
+ Bold and Italic
+ <p>This content is escaped <b><i>HTML</i></b></p>
+ This content comes from CDATA
]]>
+
\ No newline at end of file
diff --git a/TestFiles/DA/DA289-bold-underline.xml b/TestFiles/DA/DA289-bold-underline.xml
new file mode 100644
index 00000000..9f94e7f7
--- /dev/null
+++ b/TestFiles/DA/DA289-bold-underline.xml
@@ -0,0 +1,5 @@
+
+ Bold and Underline
+ <p>This content is escaped <b><u>HTML</u></b></p>
+ This content comes from CDATA]]>
+
\ No newline at end of file
diff --git a/TestFiles/DA/DA289-bold.xml b/TestFiles/DA/DA289-bold.xml
new file mode 100644
index 00000000..c3b8bc10
--- /dev/null
+++ b/TestFiles/DA/DA289-bold.xml
@@ -0,0 +1,5 @@
+
+ Bold
+ <p>This content is escaped <b>HTML</b></p>
+ This content comes from CDATA]]>
+
\ No newline at end of file
diff --git a/TestFiles/DA/DA289-emphasis.xml b/TestFiles/DA/DA289-emphasis.xml
new file mode 100644
index 00000000..a06ae5e6
--- /dev/null
+++ b/TestFiles/DA/DA289-emphasis.xml
@@ -0,0 +1,5 @@
+
+ Emphasis
+ <p>This content is escaped <em>HTML</em></p>
+ This content comes from CDATA]]>
+
\ No newline at end of file
diff --git a/TestFiles/DA/DA289-hyperlink-bold.xml b/TestFiles/DA/DA289-hyperlink-bold.xml
new file mode 100644
index 00000000..0ce58d7d
--- /dev/null
+++ b/TestFiles/DA/DA289-hyperlink-bold.xml
@@ -0,0 +1,5 @@
+
+ Hyperlink and Bold
+ <b><a href="https://www.bbc.co.uk">BBC</a></b>
+ BBC]]>
+
\ No newline at end of file
diff --git a/TestFiles/DA/DA289-hyperlink-italic.xml b/TestFiles/DA/DA289-hyperlink-italic.xml
new file mode 100644
index 00000000..32a3707d
--- /dev/null
+++ b/TestFiles/DA/DA289-hyperlink-italic.xml
@@ -0,0 +1,5 @@
+
+ Hyperlink and Italic
+ <i><a href="https://www.bbc.co.uk">BBC</a></i>
+ BBC]]>
+
\ No newline at end of file
diff --git a/TestFiles/DA/DA289-hyperlink-no-protocol.xml b/TestFiles/DA/DA289-hyperlink-no-protocol.xml
new file mode 100644
index 00000000..d934f367
--- /dev/null
+++ b/TestFiles/DA/DA289-hyperlink-no-protocol.xml
@@ -0,0 +1,5 @@
+
+ Hyperlink with No Protocol
+ <a href="www.bbc.co.uk">BBC</a>
+ BBC]]>
+
\ No newline at end of file
diff --git a/TestFiles/DA/DA289-hyperlink-underline.xml b/TestFiles/DA/DA289-hyperlink-underline.xml
new file mode 100644
index 00000000..bea6118b
--- /dev/null
+++ b/TestFiles/DA/DA289-hyperlink-underline.xml
@@ -0,0 +1,5 @@
+
+ Hyperlink and Underline
+ <u><a href="https://www.bbc.co.uk">BBC</a></u>
+ BBC]]>
+
\ No newline at end of file
diff --git a/TestFiles/DA/DA289-hyperlink.xml b/TestFiles/DA/DA289-hyperlink.xml
new file mode 100644
index 00000000..9b6db871
--- /dev/null
+++ b/TestFiles/DA/DA289-hyperlink.xml
@@ -0,0 +1,5 @@
+
+ Hyperlink
+ <a href="https://www.bbc.co.uk">BBC</a>
+ BBC]]>
+
\ No newline at end of file
diff --git a/TestFiles/DA/DA289-invalid.xml b/TestFiles/DA/DA289-invalid.xml
new file mode 100644
index 00000000..ab495296
--- /dev/null
+++ b/TestFiles/DA/DA289-invalid.xml
@@ -0,0 +1,6 @@
+
+ Invalid XHTML
+ This is NOT valid XHTML.<br>But is Valid HTML.
+
+ But is Valid HTML.]]>
+
\ No newline at end of file
diff --git a/TestFiles/DA/DA289-italic-underline.xml b/TestFiles/DA/DA289-italic-underline.xml
new file mode 100644
index 00000000..72c846b3
--- /dev/null
+++ b/TestFiles/DA/DA289-italic-underline.xml
@@ -0,0 +1,5 @@
+
+ Italic and Underline
+ <p>This content is escaped <i><u>HTML</u></i></p>
+ This content comes from CDATA]]>
+
\ No newline at end of file
diff --git a/TestFiles/DA/DA289-italic.xml b/TestFiles/DA/DA289-italic.xml
new file mode 100644
index 00000000..190b2ad1
--- /dev/null
+++ b/TestFiles/DA/DA289-italic.xml
@@ -0,0 +1,5 @@
+
+ Italic
+ <p>This content is escaped <i>HTML</i></p>
+ This content comes from CDATA]]>
+
\ No newline at end of file
diff --git a/TestFiles/DA/DA289-multi-paragraph.xml b/TestFiles/DA/DA289-multi-paragraph.xml
new file mode 100644
index 00000000..30e42889
--- /dev/null
+++ b/TestFiles/DA/DA289-multi-paragraph.xml
@@ -0,0 +1,5 @@
+
+ Multiple Paragraphs
+ <p>Boggarts lavender robes, Hermione Granger <i>Fantastic Beasts</i> and Where to Find Them.</p><p>Bee in your bonnet Hand of Glory elder wand, spectacles <b>House Cup</b> Bertie Bott’s Every Flavor Beans Impedimenta.</p><p>Stunning spells tap-dancing spider Slytherin’s Heir <u>mewing kittens</u> <s>Remus Lupin</s>.</p>
+ Boggarts lavender robes, Hermione Granger Fantastic Beasts and Where to Find Them.Bee in your bonnet Hand of Glory elder wand, spectacles House Cup Bertie Bott’s Every Flavor Beans Impedimenta.
Stunning spells tap-dancing spider Slytherin’s Heir mewing kittens Remus Lupin.
]]>
+
\ No newline at end of file
diff --git a/TestFiles/DA/DA289-no-inline-styles.xml b/TestFiles/DA/DA289-no-inline-styles.xml
new file mode 100644
index 00000000..52e816cf
--- /dev/null
+++ b/TestFiles/DA/DA289-no-inline-styles.xml
@@ -0,0 +1,5 @@
+
+ No Inline Styles
+ <p>This content is escaped HTML</p>
+ This content comes from CDATA]]>
+
\ No newline at end of file
diff --git a/TestFiles/DA/DA289-not-well-formed.xml b/TestFiles/DA/DA289-not-well-formed.xml
new file mode 100644
index 00000000..2dc75079
--- /dev/null
+++ b/TestFiles/DA/DA289-not-well-formed.xml
@@ -0,0 +1,5 @@
+
+ Not Well Formed XHTML
+ <b><i>This is NOT well formed XHTML.</b></i>
+ This is NOT well formed XHTML.]]>
+
\ No newline at end of file
diff --git a/TestFiles/DA/DA289-strikethrough.xml b/TestFiles/DA/DA289-strikethrough.xml
new file mode 100644
index 00000000..c23411a0
--- /dev/null
+++ b/TestFiles/DA/DA289-strikethrough.xml
@@ -0,0 +1,5 @@
+
+ Strikethrough
+ <p>This content is escaped <s>HTML</s></p>
+ This content comes from CDATA]]>
+
\ No newline at end of file
diff --git a/TestFiles/DA/DA289-strong.xml b/TestFiles/DA/DA289-strong.xml
new file mode 100644
index 00000000..430ef1a0
--- /dev/null
+++ b/TestFiles/DA/DA289-strong.xml
@@ -0,0 +1,5 @@
+
+ Strong
+ <p>This content is escaped <strong>HTML</strong></p>
+ This content comes from CDATA]]>
+
\ No newline at end of file
diff --git a/TestFiles/DA/DA289-subscript.xml b/TestFiles/DA/DA289-subscript.xml
new file mode 100644
index 00000000..aab88487
--- /dev/null
+++ b/TestFiles/DA/DA289-subscript.xml
@@ -0,0 +1,5 @@
+
+ Subscript
+ <p>This content is escaped <sub>HTML</sub></p>
+ This content comes from CDATA]]>
+
\ No newline at end of file
diff --git a/TestFiles/DA/DA289-superscript.xml b/TestFiles/DA/DA289-superscript.xml
new file mode 100644
index 00000000..c3ec767b
--- /dev/null
+++ b/TestFiles/DA/DA289-superscript.xml
@@ -0,0 +1,5 @@
+
+ Superscript
+ <p>This content is escaped <sup>HTML</sup></p>
+ This content comes from CDATA]]>
+
\ No newline at end of file
diff --git a/TestFiles/DA/DA289-underline.xml b/TestFiles/DA/DA289-underline.xml
new file mode 100644
index 00000000..24bf99eb
--- /dev/null
+++ b/TestFiles/DA/DA289-underline.xml
@@ -0,0 +1,5 @@
+
+ Underline
+ <p>This content is escaped <u>HTML</u></p>
+ This content comes from CDATA]]>
+
\ No newline at end of file
diff --git a/TestFiles/DA/DA289-xhtml-formatting.docx b/TestFiles/DA/DA289-xhtml-formatting.docx
new file mode 100644
index 00000000..26e65a25
Binary files /dev/null and b/TestFiles/DA/DA289-xhtml-formatting.docx differ