Span ParseSpan(HtmlNode node, Style style) { var span = new Span(); span.ApplyStyle(style); foreach (var child in node.ChildNodes) { span.Inlines.SafeAdd(ParseNode(child, style)); } return(span); }
Span ParseLink(HtmlNode node, Style style) { var span = new Span(); span.ApplyStyle(new Style(style) { TextAlignment = TextAlignment.Center }); var url = node.Attributes["href"]?.Value; url = url == null || url.Contains("://") ? url : $"epub://{url}"; var hyperlink = new Hyperlink { NavigateUri = url == null ? null : new Uri(url, UriKind.RelativeOrAbsolute) }; foreach (var child in node.ChildNodes) { var el = ParseNode(child, style); if (!hyperlink.Inlines.SafeAdd(el) && el is LineBreak lineBreak) { span.Inlines.Add(hyperlink); span.Inlines.Add(el); hyperlink = new Hyperlink { NavigateUri = url == null ? null : new Uri(url, UriKind.RelativeOrAbsolute), }; } } span.Inlines.Add(hyperlink); return(span); }