/// <summary> /// Create an ordered list block with the given elements. /// </summary> /// <param name="contents">Contents - each element will be a list item.</param> private ListBlock CreateOrderedListBlock(params string[] contents) { BlockParser parser = new ListBlockParser(); ListBlock block = new ListBlock(parser); block.IsOrdered = true; foreach (string item in contents) { ListItemBlock listItem = new ListItemBlock(parser); ParagraphBlock paragraph = new ParagraphBlock(new ParagraphBlockParser()); paragraph.Inline = new ContainerInline().AppendChild(new LiteralInline(item)); listItem.Add(paragraph); block.Add(listItem); } return(block); }
public void EnsureChildrenAreWritten() { // Create a list block with a single list item containing // an emphasis (italic) inline. BlockParser parser = new ListBlockParser(); ListBlock block = new ListBlock(parser); block.IsOrdered = true; string item = "item"; ListItemBlock listItem = new ListItemBlock(parser); ParagraphBlock paragraphBlock = new ParagraphBlock(new ParagraphBlockParser()); EmphasisInline emphasis = new EmphasisInline(); emphasis.DelimiterChar = '*'; emphasis.DelimiterCount = 1; emphasis.AppendChild(new LiteralInline(item)); paragraphBlock.Inline = new ContainerInline().AppendChild(emphasis); listItem.Add(paragraphBlock); block.Add(listItem); renderer.Write(pdfBuilder, block); Assert.AreEqual(1, document.LastSection.Elements.Count); Paragraph paragraph = (Paragraph)document.LastSection.Elements[0]; // Paragraph should have 3 elements: bullet, content, and linefeed. Assert.AreEqual(3, paragraph.Elements.Count); FormattedText text = paragraph.Elements[1] as FormattedText; Assert.NotNull(text); var textStyle = document.Styles[text.Style]; Assert.True(textStyle.Font.Italic); Assert.AreEqual($" 1. {item}\n", paragraph.GetRawText()); }