private static Viewbox CreateImage(HtmlNode node, string src) { var viewbox = new Viewbox { StretchDirection = StretchDirection.DownOnly }; var imgHeight = node.Attributes.GetValueInt("height"); var width = node.Attributes.GetValueInt("width"); if (imgHeight > 0) { viewbox.MaxHeight = imgHeight; } if (width > 0) { viewbox.MaxWidth = width; } viewbox.Child = new ImageEx { Source = src, Stretch = Stretch.Uniform, Background = new SolidColorBrush(Colors.Transparent), Foreground = new SolidColorBrush(Colors.Transparent), AnimateGif = true }; return viewbox; }
internal HtmlNode AddNode(HtmlTag tag) { var node = new HtmlNode(tag); Fragments.Add(node); return node; }
private static int GetSpan(HtmlNode node, string name) { if (node != null) { return node.Attributes.GetValueInt(name); } return 0; }
private static int? GetTableBorder(HtmlNode node) { var table = node?.Ascendant("table") as HtmlNode; if (table != null && !string.IsNullOrEmpty(table.Attributes.GetValue("border"))) { return table.Attributes.GetValueInt("border"); } return null; }
private static string GetImageSrc(HtmlNode node) { var regex = new Regex(@"(?:http(?:s?)://www\.youtube\.com/embed/)(?<videoid>[\w_-]*)(?:\??)(?:/?)(?:\.*)"); var src = GetIframeSrc(node); if (!string.IsNullOrEmpty(src)) { var match = regex.Match(src); if (match.Success) { return $"https://i.ytimg.com/vi/{match.Groups["videoid"].Value}/maxresdefault.jpg"; } } return null; }
protected abstract void SetScreenshot(ImageEx img, HtmlNode node);
protected override void SetScreenshot(ImageEx img, HtmlNode node) { img.Source = GetEmbebedImage("AppStudio.Uwp.Controls.HtmlBlock.channel9-screen.png"); img.Background = new SolidColorBrush(Color.FromArgb(255, 249, 203, 66)); }
private static string GetImageSrc(HtmlNode img) { if (!string.IsNullOrEmpty(img.Attributes.GetValue("src"))) { return img.Attributes.GetValue("src"); } else if (!string.IsNullOrEmpty(img.Attributes.GetValue("srcset"))) { var regex = new Regex(@"(?:(?<src>[^\""'\s,]+)\s*(?:\s+\d+[wx])(?:,\s*)?)"); var matches = regex.Matches(img.Attributes.GetValue("srcset")); if (matches.Count > 0) { var m = matches[matches.Count - 1]; return m?.Groups["src"].Value; } } return null; }
protected override void SetScreenshot(ImageEx img, HtmlNode node) { img.Source = GetImageSrc(node); }