private static Inline Convert(SyntaxTreeNode node, Func <TagNode, Inline> customMapper) { if (node is TextNode) { return(new Run(node.ToText())); } Span span; if (node is TagNode) { var custom = customMapper?.Invoke((TagNode)node); if (custom != null) { return(custom); } var inline = ToInline((TagNode)node); span = inline as Span; if (span == null) { return(inline); } } else { span = new Span(); } foreach (var inline in node.SubNodes) { span.Inlines.Add(Convert(inline, customMapper)); } return(span); }