unsafe public object Convert(object value, Type targetType, object parameter, string language) { if (value is MarkdownData) { var markdownData = value as MarkdownData; try { var categoryVisitor = new SnuDomCategoryVisitor(); ((IDomObject)markdownData.MarkdownDom).Accept(categoryVisitor); switch (categoryVisitor.Category) { case MarkdownCategory.PlainText: { var visitor = new SnuDomPlainTextVisitor(); ((IDomObject)markdownData.MarkdownDom).Accept(visitor); return MakePlain(visitor.Result); } case MarkdownCategory.Formatted: case MarkdownCategory.Full: { var visitor = new SnuDomFullUIVisitor(new SolidColorBrush(Colors.White)); ((IDomObject)markdownData.MarkdownDom).Accept(visitor); if (visitor.ResultGroup != null) return visitor.ResultGroup; else return visitor.Result; } default: return new TextBlock { Text = "" }; } } catch (Exception ex) { return MakePlain(ex.ToString()); } } else return new TextBlock { Text = "" }; }
private IEnumerable<UIElement> BuildChildUIList(IEnumerable<IDomObject> objects) { List<UIElement> results = new List<UIElement>(); foreach (var item in objects) { SnuDomCategoryVisitor categoryVisitor = new SnuDomCategoryVisitor(); item.Accept(categoryVisitor); var column = item as TableColumn; if (categoryVisitor.Category == MarkdownCategory.PlainText) { var plainTextVisitor = new SnuDomPlainTextVisitor(); //this might be a pp if (column != null) { foreach (var contents in column.Contents) { contents.Accept(plainTextVisitor); } } else if (item is SnuDom.Paragraph) { item.Accept(plainTextVisitor); } results.Add(new TextBlock { Text = plainTextVisitor.Result }); } else { var fullUIVisitor = new SnuDomFullUIVisitor(_forgroundBrush); item.Accept(fullUIVisitor); results.Add(fullUIVisitor.Result); } if (column != null) { switch (column.Alignment) { case ColumnAlignment.Center: results.Last().SetValue(FrameworkElement.HorizontalAlignmentProperty, HorizontalAlignment.Center); break; case ColumnAlignment.Left: results.Last().SetValue(FrameworkElement.HorizontalAlignmentProperty, HorizontalAlignment.Left); break; case ColumnAlignment.Right: results.Last().SetValue(FrameworkElement.HorizontalAlignmentProperty, HorizontalAlignment.Right); break; } } } return results; }
public void Visit(Quote code) { var inlineContainer = new InlineUIContainer(); SnuDomCategoryVisitor categoryVisitor = new SnuDomCategoryVisitor(); foreach (var item in code) { item.Accept(categoryVisitor); } if (categoryVisitor.Category == MarkdownCategory.PlainText && code.Count() == 1) { var plainTextVisitor = new SnuDomPlainTextVisitor(); foreach (var item in code) item.Accept(plainTextVisitor); inlineContainer.Child = new MarkdownQuote(plainTextVisitor.Result); } else { var fullUIVisitor = new SnuDomFullUIVisitor(_forgroundBrush); //cant be null in this category foreach (var item in code) item.Accept(fullUIVisitor); inlineContainer.Child = new MarkdownQuote(fullUIVisitor.Result); } if (_currentParagraph == null) { MaybeSplitForParagraph(); } else { _currentParagraph.Inlines.Add(new Windows.UI.Xaml.Documents.LineBreak()); } _currentParagraph.Inlines.Add(inlineContainer); _currentParagraph.Inlines.Add(new Windows.UI.Xaml.Documents.LineBreak()); }
public void Visit(Link link) { var inlineContainer = new InlineUIContainer(); SnuDomCategoryVisitor categoryVisitor = new SnuDomCategoryVisitor(); if (link.Display != null) { foreach (var item in link.Display) { item.Accept(categoryVisitor); } } if (categoryVisitor.Category == MarkdownCategory.PlainText) { var plainTextVisitor = new SnuDomPlainTextVisitor(); if (link.Display != null) { foreach (var item in link.Display) item.Accept(plainTextVisitor); } else plainTextVisitor.Result = link.Url; inlineContainer.Child = new MarkdownLink(link.Url, plainTextVisitor.Result); } else { var fullUIVisitor = new SnuDomFullUIVisitor(_forgroundBrush); //cant be null in this category foreach (var item in link.Display) item.Accept(fullUIVisitor); inlineContainer.Child = new MarkdownLink(link.Url, fullUIVisitor.Result); } _currentParagraph.Inlines.Add(inlineContainer); }