diff --git a/src/Markdig.Tests/MiscTests.cs b/src/Markdig.Tests/MiscTests.cs index 77b95059..e9c5a70e 100644 --- a/src/Markdig.Tests/MiscTests.cs +++ b/src/Markdig.Tests/MiscTests.cs @@ -337,4 +337,53 @@ public void TestGridTableShortLine() "; TestParser.TestSpec(input, expected, new MarkdownPipelineBuilder().UseGridTables().Build()); } + + [Test] + public void TestDefinitionListInListItemWithBlankLine() + { + var input = @" +- + + term + : definition +"; + + var expected = @"
Note
+[!NOTE] +The second one is not a note.
+++"; + TestParser.TestSpec(input, expected, new MarkdownPipelineBuilder().UseAlertBlocks().Build()); + } } diff --git a/src/Markdig/Extensions/Alerts/AlertInlineParser.cs b/src/Markdig/Extensions/Alerts/AlertInlineParser.cs index 6f95c5b6..faf56859 100644 --- a/src/Markdig/Extensions/Alerts/AlertInlineParser.cs +++ b/src/Markdig/Extensions/Alerts/AlertInlineParser.cs @@ -29,7 +29,8 @@ public override bool Match(InlineProcessor processor, ref StringSlice slice) // We expect the alert to be the first child of a quote block. Example: // > [!NOTE] // > This is a note - if (processor.Block is not ParagraphBlock paragraphBlock || paragraphBlock.Parent is not QuoteBlock quoteBlock || paragraphBlock.Inline?.FirstChild != null) + if (processor.Block is not ParagraphBlock paragraphBlock || paragraphBlock.Parent is not QuoteBlock quoteBlock || paragraphBlock.Inline?.FirstChild != null + || quoteBlock is AlertBlock || quoteBlock.Parent is not MarkdownDocument) { return false; } diff --git a/src/Markdig/Extensions/DefinitionLists/DefinitionListParser.cs b/src/Markdig/Extensions/DefinitionLists/DefinitionListParser.cs index 0985ed8d..bb3af8cf 100644 --- a/src/Markdig/Extensions/DefinitionLists/DefinitionListParser.cs +++ b/src/Markdig/Extensions/DefinitionLists/DefinitionListParser.cs @@ -105,13 +105,20 @@ public override BlockState TryOpen(BlockProcessor processor) { var index = previousParent.IndexOf(paragraphBlock) - 1; if (index < 0) return null; - var lastBlock = previousParent[index]; - if (lastBlock is BlankLineBlock) + switch (previousParent[index]) { - lastBlock = previousParent[index - 1]; - previousParent.RemoveAt(index); + case DefinitionList definitionList: + return definitionList; + + case BlankLineBlock: + if (index > 0 && previousParent[index - 1] is DefinitionList definitionList2) + { + previousParent.RemoveAt(index); + return definitionList2; + } + break; } - return lastBlock as DefinitionList; + return null; } public override BlockState TryContinue(BlockProcessor processor, Block block)++[!NOTE] +Also not a note.
+