private Block Convert(CommonMark.Syntax.Block block) { switch (block.Tag) { case BlockTag.BlockQuote: return(new Section(Fill(block.FirstChild)) { Margin = new Thickness(20, 0, 20, 0) }); case BlockTag.List: var list = new List(); var item = block.FirstChild; while (item != null) { list.ListItems.Add(ConvertListItem(block)); item = item.NextSibling; } return(list); case BlockTag.FencedCode: case BlockTag.IndentedCode: case BlockTag.HtmlBlock: return(new BlockUIContainer(new TextBox { IsReadOnly = true, Text = block.StringContent.ToString() })); case BlockTag.Paragraph: return(new Paragraph(Fill(block.InlineContent)) { TextAlignment = TextAlignment.Left }); case BlockTag.AtxHeading: case BlockTag.SetextHeading: return(new Paragraph(Fill(block.InlineContent)) { TextAlignment = TextAlignment.Left, FontSize = SystemFonts.MessageFontSize * (7 - block.Heading.Level) / 2 }); case BlockTag.ThematicBreak: return(new Section { BorderBrush = SystemColors.WindowTextBrush, BorderThickness = new Thickness(0, 2, 0, 0), Margin = new Thickness(5) }); case BlockTag.ReferenceDefinition: return(new Section()); } throw new NotImplementedException(); }
private Block Fill(CommonMark.Syntax.Block firstChild) { var section = new Section(); while (firstChild != null) { section.Blocks.Add(Convert(firstChild)); firstChild = firstChild.NextSibling; } return(section); }
private ListItem ConvertListItem(CommonMark.Syntax.Block block) { var item = new ListItem { TextAlignment = TextAlignment.Left }; for (var child = block.FirstChild; child != null; child = child.NextSibling) { item.Blocks.Add(Convert(child)); } if (block.InlineContent != null) { item.Blocks.Add(new Paragraph(Fill(block.InlineContent)) { TextAlignment = TextAlignment.Left }); } return(item); }