Skip to content

Commit

Permalink
Merge pull request #843 from snnz/fix-deflists
Browse files Browse the repository at this point in the history
Fixes exception in DefinitionListParser.GetCurrentDefinitionList()
  • Loading branch information
xoofx authored Jan 6, 2025
2 parents 9b3f442 + c488aca commit d53fd0e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
22 changes: 22 additions & 0 deletions src/Markdig.Tests/MiscTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,28 @@ public void RootInlineInTableCellHasCorrectSourceSpan()
Assert.That(paragraph.Inline.Span.End == paragraph.Inline.LastChild.Span.End);
}

[Test]
public void TestDefinitionListInListItemWithBlankLine()
{
var input = @"
-
term
: definition
";

var expected = @"<ul>
<li>
<dl>
<dt>term</dt>
<dd>definition</dd>
</dl>
</li>
</ul>
";
TestParser.TestSpec(input, expected, new MarkdownPipelineBuilder().UseDefinitionLists().Build());
}

[Test]
public void TestAlertWithinAlertOrNestedBlock()
{
Expand Down
17 changes: 12 additions & 5 deletions src/Markdig/Extensions/DefinitionLists/DefinitionListParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d53fd0e

Please sign in to comment.