From 3e0c72f0430cb58d7aa9caf325bd780325229e17 Mon Sep 17 00:00:00 2001 From: Sergey Nozhenko Date: Fri, 3 Jan 2025 03:30:49 +0300 Subject: [PATCH] Fixes exception in DefinitionListParser.GetCurrentDefinitionList() --- .../DefinitionLists/DefinitionListParser.cs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) 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)