private View Render(ListBlock list, int index, ListItemBlock itemBlock, MarkdownTheme theme) { var stack = new StackLayout() { Spacing = theme.Margin }; var horizontalStack = new StackLayout { Orientation = StackOrientation.Horizontal, Margin = new Thickness(theme.Margin, 0, 0, 0) }; var bullet = new Label { Text = list.IsOrdered ? $"{index}." : "\u2981", FontSize = theme.Paragraph.FontSize, TextColor = theme.Paragraph.ForegroundColor, VerticalOptions = LayoutOptions.Start, HorizontalOptions = LayoutOptions.Center, HorizontalTextAlignment = TextAlignment.Center, VerticalTextAlignment = TextAlignment.Center, LineBreakMode = LineBreakMode.NoWrap, Margin = theme.ListItemThickness }; horizontalStack.Children.Add(bullet); horizontalStack.Children.Add(_render.Render(itemBlock.AsEnumerable(), theme)); stack.Children.Add(horizontalStack); return(stack); }
private static MarkdownStyle GetHeadingStyle(HeadingBlock block, MarkdownTheme theme) { MarkdownStyle style; switch (block.Level) { case 1: style = theme.Heading1; break; case 2: style = theme.Heading2; break; case 3: style = theme.Heading3; break; case 4: style = theme.Heading4; break; case 5: style = theme.Heading5; break; default: style = theme.Heading6; break; } return(style); }
public View Render <T>(T block, MarkdownTheme theme) where T : Block { switch (block) { case HeadingBlock heading: return(new Heading(_navigateToLink).Render(heading, theme)); case ParagraphBlock paragraph: return(new Paragraph(_navigateToLink).Render(paragraph, theme)); case ListBlock list: return(new List(this, _navigateToLink).Render(list, theme)); case CodeBlock code: return(new Code(_navigateToLink).Render(code, theme)); case ThematicBreakBlock @break: return(new ThematicBreak().Render(@break, theme)); case Markdig.Extensions.Tables.Table table: return(new Table(this, _navigateToLink).Render(table, @theme)); default: return(new Unknown().Render(block, theme)); } }
public void Setup() { _defaultTheme = new MarkdownTheme("iOS"); var innerRenderer = new InnerRender(); _markdownRenderer = new MarkdownNativeRenderer(innerRenderer); }
public SamplePageViewModel() { themeTemplate = new LightMarkdownTheme(); Markdown = embeded; InitSource(); InitSettings(); }
public View Render(Markdig.Extensions.Tables.Table block, MarkdownTheme theme) { var grid = new Grid(); AddRowsAndColumnsDefinitions(block, grid); RenderRowsAndColumns(block, grid, theme); return(grid); }
private Span[] CreateSpans( Inline inline, string family, FontAttributes attributes, Color foregroundColor, Color backgroundColor, float size, MarkdownTheme theme) { switch (inline) { case LiteralInline literal: return(new[] { new Span { Text = literal.Content.Text.Substring(literal.Content.Start, literal.Content.Length), FontAttributes = attributes, ForegroundColor = foregroundColor, BackgroundColor = backgroundColor, FontSize = size, FontFamily = family, LineHeight = theme.LineHeight } }); case EmphasisInline emphasis: var childAttributes = attributes | (emphasis.DelimiterCount == 2 ? FontAttributes.Bold : FontAttributes.Italic); return(emphasis.SelectMany(x => CreateSpans(x, family, childAttributes, foregroundColor, backgroundColor, size, theme)).ToArray()); case LineBreakInline _: return(new[] { new Span { Text = "\n" } }); case LinkInline link: var url = link.Url; var spans = link.SelectMany(x => CreateSpans( x, theme.Link.FontFamily ?? family, theme.Link.Attributes, theme.Link.ForegroundColor, theme.Link.BackgroundColor, size, theme)).ToArray(); _links.Add(new KeyValuePair <string, string>(string.Join(string.Empty, spans.Select(x => x.Text)), url)); return(spans); default: return(Enumerable.Empty <Span>().ToArray()); } }
public View Render(ThematicBreakBlock block, MarkdownTheme theme) { var style = theme.Separator; return(new BoxView { HeightRequest = style.BorderSize, BackgroundColor = style.BorderColor, }); }
public void ThemeSet_EmptyMarkDown_ShouldNotCallRender() { // given var theme = new MarkdownTheme("Android"); var control = new MarkdownContentView(_nativeMarkdownNativeRenderer); // when control.Theme = theme; // then _nativeMarkdownNativeRenderer.Received(0).Render(string.Empty, theme); }
private View Render(ListBlock list, int index, ListItemBlock itemBlock, MarkdownTheme theme) { var stack = new StackLayout() { Spacing = theme.Margin }; var horizontalStack = new StackLayout { Orientation = StackOrientation.Horizontal, Margin = new Thickness(theme.Margin, 0, 0, 0), }; View bullet; if (list.IsOrdered) { bullet = new Label { Text = $"{index}.", FontSize = theme.Paragraph.FontSize, TextColor = theme.Paragraph.ForegroundColor, VerticalOptions = LayoutOptions.Start, HorizontalOptions = LayoutOptions.End, HorizontalTextAlignment = TextAlignment.Center, VerticalTextAlignment = TextAlignment.Center, LineBreakMode = LineBreakMode.NoWrap, Margin = new Thickness(0, 3, 0, 0) }; } else { bullet = new BoxView { WidthRequest = 4, HeightRequest = 4, Margin = new Thickness(0, 10, 0, 0), BackgroundColor = theme.Paragraph.ForegroundColor, VerticalOptions = LayoutOptions.Start, HorizontalOptions = LayoutOptions.Center }; } horizontalStack.Children.Add(bullet); horizontalStack.Children.Add(_render.Render(itemBlock.AsEnumerable(), theme)); stack.Children.Add(horizontalStack); return(stack); }
public View Render(ListBlock block, MarkdownTheme theme) { var stack = new StackLayout() { Spacing = theme.Margin }; for (var i = 0; i < block.Count(); i++) { var item = block.ElementAt(i); if (item is ListItemBlock itemBlock) { stack.Children.Add(Render(block, i + 1, itemBlock, theme)); } } return(stack); }
public View Render(IEnumerable <Block> blocks, MarkdownTheme theme) { var stack = new StackLayout() { Spacing = theme.Margin }; foreach (var block in blocks) { var view = Render(block, theme); if (view == null) { continue; } stack.Children.Add(view); } return(stack); }
public View Render(HeadingBlock block, MarkdownTheme theme) { var style = GetHeadingStyle(block, theme); var formatParameters = new FormatParameters() { ContainerInline = block.Inline, Family = style.FontFamily, Attributes = style.Attributes, ForegroundColor = style.ForegroundColor, BackgroundColor = style.BackgroundColor, Size = style.FontSize, Theme = theme }; var label = new Label { FormattedText = CreateFormatted(formatParameters) }; if (style.BorderSize <= 0) { return(label); } AttachLinks(label); var headingStack = new StackLayout(); headingStack.Children.Add(label); headingStack.Children.Add(new BoxView { HeightRequest = style.BorderSize, BackgroundColor = style.BorderColor, }); return(headingStack); }
public View Render(ParagraphBlock block, MarkdownTheme theme) { var style = theme.Paragraph; var formatParameters = new FormatParameters() { ContainerInline = block.Inline, Family = style.FontFamily, Attributes = style.Attributes, ForegroundColor = style.ForegroundColor, BackgroundColor = style.BackgroundColor, Size = style.FontSize, Theme = theme }; var label = new Label { FormattedText = CreateFormatted(formatParameters) }; AttachLinks(label); return(label); }
public View Render(CodeBlock block, MarkdownTheme theme) { var style = theme.Code; var label = new Label() { TextColor = style.ForegroundColor, FontAttributes = style.Attributes, FontFamily = style.FontFamily, FontSize = style.FontSize, Text = string.Join(Environment.NewLine, block.Lines), }; var frame = new Frame() { CornerRadius = 3, HasShadow = false, Padding = theme.Margin, BackgroundColor = style.BackgroundColor, Content = label }; return(frame); }
public void MarkdownSet_ValidMarkdown_ShouldNotCallRender() { // given const string markdown = "This is a paragraph"; var theme = new MarkdownTheme("Android"); var view = new BoxView(); _nativeMarkdownNativeRenderer.Render(markdown, Arg.Any <MarkdownTheme>()).Returns(new[] { view }); // when var control = new MarkdownContentView(_nativeMarkdownNativeRenderer) { Theme = theme, Markdown = markdown }; // then _nativeMarkdownNativeRenderer.Received(1).Render(markdown, theme); var content = control.Content as StackLayout; content.ShouldNotBeNull(); content.Children.ShouldNotBeEmpty(); _ = content.Children.Contains(view); }
public View Render(Block block, MarkdownTheme theme) { return(new BoxView()); }
private void RenderRowsAndColumns(Markdig.Extensions.Tables.Table block, Grid grid, MarkdownTheme theme) { for (var rowIndex = 0; rowIndex < block.Count; rowIndex++) { var rowBlock = block.ElementAt(rowIndex); if (!(rowBlock is TableRow row)) { continue; } for (var columnIndex = 0; columnIndex < row.Count; columnIndex++) { var columnBlock = row.ElementAt(columnIndex); if (!(columnBlock is TableCell cell)) { continue; } var cellContent = cell.AsEnumerable(); var child = _render.Render(cellContent, theme); grid.Children.Add(child, columnIndex, rowIndex); } } }