Skip to content

Commit

Permalink
Merge pull request #1 from MalcolmJohnston/feature/document-assembler…
Browse files Browse the repository at this point in the history
…-HTML-support-via-HtmlToWmlConverter

Feature/document assembler html support via html to wml converter
  • Loading branch information
MalcolmJohnston authored Nov 26, 2024
2 parents 2605f71 + 33499a5 commit 5c013d8
Show file tree
Hide file tree
Showing 5 changed files with 216 additions and 352 deletions.
42 changes: 23 additions & 19 deletions Clippit/Html/HtmlToWmlConverterCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ private static object NormalizeTransform(XNode node)
return node;
}

private enum NextExpected
internal enum NextExpected
{
Paragraph,
Run,
Expand Down Expand Up @@ -2830,7 +2830,7 @@ string pictureDescription
</a:graphicData>
</a:graphic>
#endif
private static XElement GetParagraphProperties(
internal static XElement GetParagraphProperties(
XElement blockLevelElement,
string styleName,
HtmlToWmlConverterSettings settings
Expand Down Expand Up @@ -3041,14 +3041,18 @@ private static XElement[] GetSpacingProperties(XElement paragraph, HtmlToWmlConv
return new XElement[] { spacing, ind, contextualSpacing };
}

private static XElement GetRunProperties(XText textNode, HtmlToWmlConverterSettings settings)
internal static XElement GetRunProperties(XText textNode, HtmlToWmlConverterSettings settings)
{
var parent = textNode.Parent;
var rPr = GetRunProperties(parent, settings);
return rPr;
if (parent != null)
{
return GetRunProperties(parent, settings);
}

return new XElement(W.rPr);
}

private static XElement GetRunProperties(XElement element, HtmlToWmlConverterSettings settings)
internal static XElement GetRunProperties(XElement element, HtmlToWmlConverterSettings settings)
{
var colorProperty = element.GetProp("color");
var fontFamilyProperty = element.GetProp("font-family");
Expand All @@ -3060,15 +3064,15 @@ private static XElement GetRunProperties(XElement element, HtmlToWmlConverterSet
var letterSpacingProperty = element.GetProp("letter-spacing");
var directionProp = element.GetProp("direction");

var colorPropertyString = colorProperty.ToString();
var colorPropertyString = colorProperty?.ToString();
var fontFamilyString = GetUsedFontFromFontFamilyProperty(fontFamilyProperty);
var fontSizeTPoint = GetUsedSizeFromFontSizeProperty(fontSizeProperty);
var textDecorationString = textDecorationProperty.ToString();
var fontStyleString = fontStyleProperty.ToString();
var fontWeightString = fontWeightProperty.ToString().ToLower();
var backgroundColorString = backgroundColorProperty.ToString().ToLower();
var letterSpacingString = letterSpacingProperty.ToString().ToLower();
var directionString = directionProp.ToString().ToLower();
var textDecorationString = textDecorationProperty?.ToString();
var fontStyleString = fontStyleProperty?.ToString();
var fontWeightString = fontWeightProperty?.ToString().ToLower();
var backgroundColorString = backgroundColorProperty?.ToString().ToLower();
var letterSpacingString = letterSpacingProperty?.ToString().ToLower();
var directionString = directionProp?.ToString().ToLower();

var subAncestor = element.AncestorsAndSelf(XhtmlNoNamespace.sub).Any();
var supAncestor = element.AncestorsAndSelf(XhtmlNoNamespace.sup).Any();
Expand All @@ -3085,7 +3089,7 @@ private static XElement GetRunProperties(XElement element, HtmlToWmlConverterSet
dirAttributeString = dirAttribute.Value.ToLower();

XElement shd = null;
if (backgroundColorString != "transparent")
if (backgroundColorString != null && backgroundColorString != "transparent")
shd = new XElement(
W.shd,
new XAttribute(W.val, "clear"),
Expand Down Expand Up @@ -3155,7 +3159,7 @@ private static XElement GetRunProperties(XElement element, HtmlToWmlConverterSet
rStyle = new XElement(W.rStyle, new XAttribute(W.val, "Hyperlink"));

XElement spacing = null;
if (letterSpacingProperty.IsNotNormal)
if (letterSpacingProperty != null && letterSpacingProperty.IsNotNormal)
spacing = new XElement(W.spacing, new XAttribute(W.val, (long)(Twip)letterSpacingProperty));

XElement rtl = null;
Expand Down Expand Up @@ -3191,9 +3195,9 @@ private static XElement GetRunProperties(XElement element, HtmlToWmlConverterSet
// todo this is not right - needs to be rationalized for all characters in an entire paragraph.
// if there is text like <p>abc <em> def </em> ghi</p> then there needs to be just one space between abc and def, and between
// def and ghi.
private static string GetDisplayText(XText node, bool preserveWhiteSpace)
internal static string GetDisplayText(XText node, bool preserveWhiteSpace)
{
var textTransform = node.Parent.GetProp("text-transform").ToString();
var textTransform = node.Parent.GetProp("text-transform")?.ToString();
var isFirst = node.Parent.Name == XhtmlNoNamespace.p && node == node.Parent.FirstNode;
var isLast = node.Parent.Name == XhtmlNoNamespace.p && node == node.Parent.LastNode;

Expand Down Expand Up @@ -3884,7 +3888,7 @@ private static XElement GetTableRowProperties(XElement element)
return trPr;
}

private static XAttribute GetXmlSpaceAttribute(string value)
internal static XAttribute GetXmlSpaceAttribute(string value)
{
if (value.StartsWith(" ") || value.EndsWith(" "))
return new XAttribute(XNamespace.Xml + "space", "preserve");
Expand Down Expand Up @@ -4331,7 +4335,7 @@ private static XElement GetBackgroundProperty(XElement element)
var color = element.GetProp("background-color");

// todo this really should test against default background color
if (color.ToString() != "transparent")
if (color != null && color.ToString() != "transparent")
{
var hexString = color.ToString();
var shd = new XElement(
Expand Down
Loading

0 comments on commit 5c013d8

Please sign in to comment.