예제 #1
0
        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);
        }
예제 #2
0
        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);
        }