コード例 #1
0
ファイル: ListBlockParser.cs プロジェクト: obarlik/markdig
        private BlockState TryContinueListItem(BlockProcessor state, ListItemBlock listItem)
        {
            var list = (ListBlock)listItem.Parent;

            // Allow all blanks lines if the last block is a fenced code block
            // Allow 1 blank line inside a list
            // If > 1 blank line, terminate this list
            if (state.IsBlankLine)
            {
                if (state.CurrentBlock != null && state.CurrentBlock.IsBreakable)
                {
                    if (!(state.NextContinue is ListBlock))
                    {
                        list.CountAllBlankLines++;
                        listItem.Add(new BlankLineBlock());
                    }
                    list.CountBlankLinesReset++;
                }

                if (list.CountBlankLinesReset == 1 && listItem.ColumnWidth < 0)
                {
                    state.Close(listItem);

                    // Leave the list open
                    list.IsOpen = true;
                    return(BlockState.Continue);
                }

                // Update list-item source end position
                listItem.UpdateSpanEnd(state.Line.End);

                return(BlockState.Continue);
            }

            list.CountBlankLinesReset = 0;

            int columnWidth = listItem.ColumnWidth;

            if (columnWidth < 0)
            {
                columnWidth = -columnWidth;
            }

            if (state.Indent >= columnWidth)
            {
                if (state.Indent > columnWidth && state.IsCodeIndent)
                {
                    state.GoToColumn(state.ColumnBeforeIndent + columnWidth);
                }

                // Update list-item source end position
                listItem.UpdateSpanEnd(state.Line.End);

                return(BlockState.Continue);
            }

            return(BlockState.None);
        }
コード例 #2
0
        /// <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);
        }
コード例 #3
0
        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());
        }