Exemple #1
0
        /// <summary>
        /// Render the given list block to the PDF document.
        /// </summary>
        /// <param name="renderer">The PDF renderer.</param>
        /// <param name="html">The list block to be renderered.</param>
        protected override void Write(PdfBuilder renderer, ListBlock list)
        {
            renderer.StartNewParagraph();

            int i = 1;

            // Implicit cast from Block to ListItemBlock here. Markdig's builtin html
            // renderer also makes this assumption.
            foreach (ListItemBlock child in list)
            {
                // Write the bullet.
                // todo: should use proper indentation (\t) here.
                string bullet = list.IsOrdered ? $"{i}." : list.BulletType.ToString();

                // Calling StartListItem() will prevent the list item's contents
                // from creating a new paragraph.
                renderer.StartListItem($" {bullet} ");

                // Write the contents of the list item.
                renderer.WriteChildren(child);

                // Write a newline character. We don't want multiple list items on the same line.
                // renderer.AppendText(Environment.NewLine, TextStyle.Normal, false);
                renderer.FinishListItem();

                i++;
            }
            renderer.StartNewParagraph();
        }
Exemple #2
0
        public void TestFinishListItem()
        {
            string bullet     = "-";
            string bulletText = "bullet point text";
            string serialText = "this goes after the list item.";

            builder.StartListItem(bullet);
            builder.AppendText(bulletText, TextStyle.Normal);
            builder.FinishListItem();
            builder.AppendText(serialText, TextStyle.Normal);

            Assert.AreEqual(1, doc.LastSection.Elements.Count);
            Paragraph paragraph = (Paragraph)doc.LastSection.Elements[0];

            Assert.AreEqual(4, paragraph.Elements.Count);

            // First element is the bullet.
            Text insertedBullet = (Text)paragraph.Elements[0];

            Assert.AreEqual(bullet, insertedBullet.Content);

            // Second element is the list item text.
            FormattedText listItem = (FormattedText)paragraph.Elements[1];

            Assert.AreEqual(1, listItem.Elements.Count);
            Text listItemText = (Text)listItem.Elements[0];

            Assert.AreEqual(bulletText, listItemText.Content);

            // Third element is a newline character.
            Character newline = (Character)paragraph.Elements[2];

            Assert.AreEqual(SymbolName.LineBreak, newline.SymbolName);

            // Fourth element is the text inserted after the list item.
            FormattedText serialContent = (FormattedText)paragraph.Elements[3];

            Assert.AreEqual(1, serialContent.Elements.Count);
            Text rawText = (Text)serialContent.Elements[0];

            Assert.AreEqual(serialText, rawText.Content);
        }