) do not.
+ // In WPF, all of these map to Paragraphs that *does* have a default margin.
+ if (node?.Token?.Name != "p")
+ para.Margin = new Thickness(0);
ApplyStyle(para, node);
para.Inlines.AddRange(VisitAndAddInlines(node.Children));
- AdjustSpacing(para, node);
return para;
}
@@ -140,7 +142,7 @@ private static Block VisitBlock(MarkupNode node)
return new BlockUIContainer(new Separator());
case MarkupType.Table:
- var table = new Table();
+ var table = new Table { Margin = new Thickness(0) };
var columnCount = node.Children.Max(rowNode => rowNode.Children.Count);
for (int i = 0; i < columnCount; i++)
table.Columns.Add(new TableColumn());
@@ -221,26 +223,15 @@ private static Inline VisitInline(MarkupNode node)
return new LineBreak();
case MarkupType.Text:
- return new Run(node.Content);
+ var run = new Run(node.Content);
+ ApplyStyle(run, node);
+ return run;
default:
return new Run(); // placeholder for unsupported types
}
}
- private static void AdjustSpacing(Paragraph para, MarkupNode? blockNode)
- {
- // WPF LineBreaks behave differently from HTML breaks.
- // In HTML, a
is needed inside empty blocks to prevent block height from collapsing.
- // But in WPF, that
just adds an unwanted second line, so we skip it.
- if (para.Inlines.Count == 1 && para.Inlines.First() is LineBreak lastBreak)
- para.Inlines.Remove(lastBreak);
- // In HTML,
has default margin but other blocks (like
) do not.
- // In WPF, all of these map to Paragraphs that *does* have a default margin.
- if (blockNode?.Token?.Name != "p")
- para.Margin = new Thickness(0);
- }
-
private static bool HasAnyBlocks(MarkupNode node)
{
return node.Children.Any(c => MapsToBlock(c) || HasAnyBlocks(c));