/// <summary> /// Renders a list element. /// </summary> /// <param name="element"></param> /// <param name="currentBlocks"></param> private void RenderListElement(ListElementBlock element, BlockCollection currentBlocks) { // Create a grid for the dot and the text Grid grid = new Grid(); // The first column for the dot the second for the text grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Auto) }); grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) }); // Make the dot container and the new text box TextBlock dotText = new TextBlock(); dotText.Text = element.ListBullet; Grid.SetColumn(dotText, 0); // Add the indent dotText.Margin = new Thickness(12 * element.ListIndent, 2, 0, 2); grid.Children.Add(dotText); RichTextBlock listText = new RichTextBlock(); Grid.SetColumn(listText, 1); // Give the text some space from the dot and also from the top and bottom listText.Margin = new Thickness(6, 2, 0, 2); grid.Children.Add(listText); // Make the inline container InlineUIContainer uiConainter = new InlineUIContainer(); uiConainter.Child = grid; // Make a paragraph to hold our list Paragraph blockParagraph = new Paragraph(); blockParagraph.Inlines.Add(uiConainter); // Make a paragraph to hold our list test Paragraph inlineParagraph = new Paragraph(); listText.Blocks.Add(inlineParagraph); // Add it to the blocks currentBlocks.Add(blockParagraph); // Render the children into the rich. bool trimTextStart = true; RenderInlineChildren(element, inlineParagraph.Inlines, ref trimTextStart); }
/// <summary> /// Called by all elements to find the next element to parse out of the markdown given a startingPos and an ending Pos /// </summary> /// <param name="markdown"></param> /// <param name="startingPos"></param> /// <param name="endingPost"></param> /// <returns></returns> public static MarkdownBlock FindNextBlock(ref string markdown, ref int startingPos, int endingPos) { // We need to look at the start of this current block and figure out what type it is. // Find the next char that isn't a \n, \r, or ' ', keep track of white space int spaceCount = 0; while (markdown.Length > startingPos && endingPos > startingPos && (markdown[startingPos] == '\r' || markdown[startingPos] == '\n' || Char.IsWhiteSpace(markdown[startingPos]))) { // If we find a space count it for the indent rules. If not reset the count. spaceCount = markdown[startingPos] == ' ' ? spaceCount + 1 : 0; startingPos++; } if (CodeBlock.CanHandleBlock(ref markdown, startingPos, endingPos, spaceCount)) { return(new CodeBlock()); } if (QuoteBlock.CanHandleBlock(ref markdown, startingPos, endingPos)) { return(new QuoteBlock()); } if (HeaderBlock.CanHandleBlock(ref markdown, startingPos, endingPos)) { return(new HeaderBlock()); } if (ListElementBlock.CanHandleBlock(ref markdown, startingPos, endingPos)) { return(new ListElementBlock()); } if (HorizontalRuleBlock.CanHandleBlock(ref markdown, startingPos, endingPos)) { return(new HorizontalRuleBlock()); } if (LineBreakBlock.CanHandleBlock(ref markdown, startingPos, endingPos)) { return(new LineBreakBlock()); } // If we can't match any of these just make a new paragraph. return(new ParagraphBlock()); }