Skip to content

Commit d53fd0e

Browse files
authored
Merge pull request #843 from snnz/fix-deflists
Fixes exception in DefinitionListParser.GetCurrentDefinitionList()
2 parents 9b3f442 + c488aca commit d53fd0e

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

src/Markdig.Tests/MiscTests.cs

+22
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,28 @@ public void RootInlineInTableCellHasCorrectSourceSpan()
318318
Assert.That(paragraph.Inline.Span.End == paragraph.Inline.LastChild.Span.End);
319319
}
320320

321+
[Test]
322+
public void TestDefinitionListInListItemWithBlankLine()
323+
{
324+
var input = @"
325+
-
326+
327+
term
328+
: definition
329+
";
330+
331+
var expected = @"<ul>
332+
<li>
333+
<dl>
334+
<dt>term</dt>
335+
<dd>definition</dd>
336+
</dl>
337+
</li>
338+
</ul>
339+
";
340+
TestParser.TestSpec(input, expected, new MarkdownPipelineBuilder().UseDefinitionLists().Build());
341+
}
342+
321343
[Test]
322344
public void TestAlertWithinAlertOrNestedBlock()
323345
{

src/Markdig/Extensions/DefinitionLists/DefinitionListParser.cs

+12-5
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,20 @@ public override BlockState TryOpen(BlockProcessor processor)
105105
{
106106
var index = previousParent.IndexOf(paragraphBlock) - 1;
107107
if (index < 0) return null;
108-
var lastBlock = previousParent[index];
109-
if (lastBlock is BlankLineBlock)
108+
switch (previousParent[index])
110109
{
111-
lastBlock = previousParent[index - 1];
112-
previousParent.RemoveAt(index);
110+
case DefinitionList definitionList:
111+
return definitionList;
112+
113+
case BlankLineBlock:
114+
if (index > 0 && previousParent[index - 1] is DefinitionList definitionList2)
115+
{
116+
previousParent.RemoveAt(index);
117+
return definitionList2;
118+
}
119+
break;
113120
}
114-
return lastBlock as DefinitionList;
121+
return null;
115122
}
116123

117124
public override BlockState TryContinue(BlockProcessor processor, Block block)

0 commit comments

Comments
 (0)