public override void ApplyStyles(DocumentStyle style, DependencyObject ctrl, HtmlFragment fragment) { var li = ctrl as Paragraph; var currentStyle = style.Li; if (!string.IsNullOrEmpty(currentStyle?.Bullet)) { currentStyle.RegisterPropertyChangedCallback(ListStyle.BulletProperty, (sender, dp) => { var r = li.Inlines[0] as Run; if (r != null) { r.Text = currentStyle?.Bullet; } }); li.Inlines.Insert(0, new Run { Text = currentStyle.Bullet }); li.Inlines.Insert(1, new Run { Text = " " }); } ApplyParagraphStyles(li, currentStyle); }
private static string AddFragments(TagReader reader, HtmlFragment parentFragment, Stack<string> openTagStack) { while (reader.Read()) { parentFragment.TryToAddText(HtmlText.Create(reader.Document, reader.PreviousTag, reader.CurrentTag)); if (reader.CurrentTag.TagType == TagType.Close && openTagStack.Any(t => t.Equals(reader.CurrentTag.Name, StringComparison.CurrentCultureIgnoreCase))) { return reader.CurrentTag.Name; } var node = parentFragment.AddNode(reader.CurrentTag); node.Parent = parentFragment; if (reader.CurrentTag.TagType == TagType.Open) { openTagStack.Push(reader.CurrentTag.Name); var lastClosed = AddFragments(reader, node, openTagStack); if (lastClosed != openTagStack.Pop()) { return lastClosed; } } } parentFragment.TryToAddText(HtmlText.Create(reader.Document, reader.CurrentTag, null)); return null; }
public override void ApplyStyles(DocumentStyle style, DependencyObject ctrl, HtmlFragment fragment) { var grid = ctrl as Grid; var vb = grid.GetChild<Viewbox>(0, 0); ApplyImageStyles(vb, GetStyle(style)); }
public override void ApplyStyles(DocumentStyle style, DependencyObject ctrl, HtmlFragment fragment) { if (!IsInline(fragment)) { ApplyImageStyles(ctrl as Viewbox, style.Img); } }
private static string AddFragments(TagReader reader, HtmlFragment parentFragment, Stack <string> openTagStack) { while (reader.Read()) { parentFragment.TryToAddText(HtmlText.Create(reader.Document, reader.PreviousTag, reader.CurrentTag)); if (reader.CurrentTag.TagType == TagType.Close && openTagStack.Any(t => t.Equals(reader.CurrentTag.Name, StringComparison.CurrentCultureIgnoreCase))) { return(reader.CurrentTag.Name); } var node = parentFragment.AddNode(reader.CurrentTag); node.Parent = parentFragment; if (reader.CurrentTag.TagType == TagType.Open) { openTagStack.Push(reader.CurrentTag.Name); var lastClosed = AddFragments(reader, node, openTagStack); if (lastClosed != openTagStack.Pop()) { return(lastClosed); } } } return(null); }
public override DependencyObject GetControl(HtmlFragment fragment) { var node = fragment as HtmlNode; var src = GetImageSrc(node); if (node != null && !string.IsNullOrEmpty(src)) { Uri uri; if (Uri.TryCreate(src, UriKind.Absolute, out uri)) { try { var viewbox = CreateImage(node, src); if (IsInline(fragment)) { return new InlineUIContainer { Child = viewbox }; } else { return viewbox; } } catch (Exception ex) { Debug.WriteLine($"Error loading img@src '{uri?.ToString()}': {ex.Message}"); } } } return null; }
public override void ApplyStyles(DocumentStyle style, DependencyObject ctrl, HtmlFragment fragment) { var column = ctrl as GridColumn; var border = column.Row.Container.GetChild<Border>(column.Index, column.Row.Index); if (border != null) { var tableBorder = GetTableBorder(fragment.AsNode()); if (tableBorder.HasValue) { border.BorderThickness = new Thickness(tableBorder.Value); border.BorderBrush = style.Table?.BorderForeground ?? new SolidColorBrush(Colors.Black); } else if (style.Table != null && !double.IsNaN(style.Table.Border.Top)) { BindingOperations.SetBinding(border, Border.BorderThicknessProperty, CreateBinding(style.Table, "Border")); BindingOperations.SetBinding(border, Border.BorderBrushProperty, CreateBinding(style.Table, "BorderForeground")); } if (style.Table != null) { BindingOperations.SetBinding(border, Border.MarginProperty, CreateBinding(style.Td, "Margin")); BindingOperations.SetBinding(border, Border.PaddingProperty, CreateBinding(style.Td, "Padding")); } } }
public override void ApplyStyles(DocumentStyle style, DependencyObject ctrl, HtmlFragment fragment) { var caption = ctrl as Paragraph; caption.TextAlignment = Parse(style.Img.HorizontalAlignment); ApplyParagraphStyles(caption, style.FigCaption); }
public override DependencyObject GetControl(HtmlFragment fragment) { return new GridColumn() { ColSpan = GetSpan(fragment.AsNode(), "colspan"), RowSpan = GetSpan(fragment.AsNode(), "rowspan"), }; }
public override DependencyObject GetControl(HtmlFragment fragment) { //LineBreak doesn't work with hyperlink return new Run { Text = Environment.NewLine }; }
public override DependencyObject GetControl(HtmlFragment fragment) { var text = fragment?.AsText(); if (text != null && !string.IsNullOrEmpty(text.Content)) { return new Run { Text = text.Content }; } return null; }
protected static string GetIframeSrc(HtmlFragment fragment) { var node = fragment.AsNode(); if (node != null) { if (node.Attributes.ContainsKey("src")) { return node.Attributes["src"]; } } return string.Empty; }
public override void ApplyStyles(DocumentStyle style, DependencyObject ctrl, HtmlFragment fragment) { if (style?.Table != null) { var grid = ctrl as Grid; BindingOperations.SetBinding(grid, Grid.HorizontalAlignmentProperty, CreateBinding(style.Table, "HorizontalAlignment")); foreach (var columnDefinition in grid.ColumnDefinitions) { BindingOperations.SetBinding(columnDefinition, ColumnDefinition.WidthProperty, CreateBinding(style.Table, "ColumnWidth")); } ApplyContainerStyles(grid, style.Table); } }
public override DependencyObject GetControl(HtmlFragment fragment) { var node = fragment as HtmlNode; if (node != null) { var grid = new Grid { HorizontalAlignment = HorizontalAlignment.Stretch, }; grid.Tapped += (sender, e) => { Launcher.LaunchUriAsync(new Uri(GetIframeSrc(node))).AsTask().FireAndForget(); }; grid.PointerEntered += (sender, e) => { Window.Current.CoreWindow.PointerCursor = _handCursor; }; grid.PointerExited += (sender, e) => { Window.Current.CoreWindow.PointerCursor = _arrowCursor; }; AddColumn(grid); AddColumn(grid); AddColumn(grid); var screenShot = GetImageControl((i) => SetScreenshot(i, node)); Grid.SetColumn(screenShot, 0); Grid.SetColumnSpan(screenShot, 3); grid.Children.Add(screenShot); var player = GetImageControl((i) => i.Source = GetPlayerImage()); Grid.SetColumn(player, 1); grid.Children.Add(player); return grid; } return null; }
private static ContainerStyle GetDocumentStyle(HtmlFragment fragment, DocumentStyle style) { if (style == null) { return null; } switch (fragment.Name.ToLowerInvariant()) { case "div": case "tbody": return style.Div; case "ul": return style.Ul; case "ol": return style.Ol; case "dl": return style.Dl; case "section": return style.Section; case "article": return style.Article; case "header": return style.Header; case "footer": return style.Footer; case "main": return style.Main; case "figure": return style.Figure; case "details": return style.Details; case "summary": return style.Summary; default: return null; } }
private static ParagraphStyle GetDocumentStyle(HtmlFragment fragment, DocumentStyle style) { if (style == null) { return null; } switch (fragment.Name.ToLowerInvariant()) { case "h1": return style.H1; case "h2": return style.H2; case "h3": return style.H3; case "h4": return style.H4; case "h5": return style.H5; case "h6": return style.H6; default: return null; } }
public abstract DependencyObject GetControl(HtmlFragment fragment);
public override DependencyObject GetControl(HtmlFragment fragment) { return new Paragraph(); }
public override void ApplyStyles(DocumentStyle style, DependencyObject ctrl, HtmlFragment fragment) { ApplyParagraphStyles(ctrl as Paragraph, style.Dt); }
public override bool Match(HtmlFragment fragment) { var src = GetIframeSrc(fragment); return fragment.Name == "iframe" && !string.IsNullOrWhiteSpace(src) && src.ToLowerInvariant().Contains("channel9.msdn.com"); }
public override DependencyObject GetControl(HtmlFragment fragment) { return new GridRow(); }
private void WriteFragments(HtmlFragment fragment, DocumentContainer parentContainer) { if (parentContainer != null) { foreach (var childFragment in fragment.Fragments) { var writer = HtmlWriterFactory.Find(childFragment); var ctrl = writer?.GetControl(childFragment); if (ctrl != null) { if (!parentContainer.CanContain(ctrl)) { var antecesorContainer = parentContainer.Find(ctrl); if (antecesorContainer == null) { continue; } else { parentContainer = antecesorContainer; } } var currentContainer = parentContainer.Append(ctrl); WriteFragments(childFragment, currentContainer); writer?.ApplyStyles(_docStyles, ctrl, childFragment); } } } }
private static bool IsInline(HtmlFragment fragment) { return fragment.Parent != null && fragment.Parent.Name == "p"; }
public static HtmlWriter Find(HtmlFragment fragment) { EnsureWriters(); return _writers.FirstOrDefault(w => w.Match(fragment)); ; }
public override void ApplyStyles(DocumentStyle style, DependencyObject ctrl, HtmlFragment fragment) { ApplyTextStyles(ctrl as Span, style.Q); }
public override void ApplyStyles(DocumentStyle style, DependencyObject ctrl, HtmlFragment fragment) { ApplyContainerStyles(ctrl as Grid, GetDocumentStyle(fragment, style)); }
public virtual bool Match(HtmlFragment fragment) { return fragment != null && !string.IsNullOrEmpty(fragment.Name) && TargetTags.Any(t => t.Equals(fragment.Name, StringComparison.CurrentCultureIgnoreCase)); }
public virtual void ApplyStyles(DocumentStyle style, DependencyObject ctrl, HtmlFragment fragment) { }
public override DependencyObject GetControl(HtmlFragment fragment) { var node = fragment as HtmlNode; if (node != null && node.Attributes.ContainsKey("href")) { Hyperlink a = new Hyperlink(); Uri uri; if (Uri.TryCreate(node.Attributes["href"], UriKind.Absolute, out uri)) { try { a.NavigateUri = uri; } catch (Exception ex) { Debug.WriteLine($"Error loading a@href '{uri?.ToString()}': {ex.Message}"); } } return a; } return null; }