mirror of
https://github.com/xoofx/markdig.git
synced 2026-02-03 21:36:36 +00:00
FindClosestBlock incorrectly returns LinkReferenceDefinitionGroup #575
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @AmadeusW on GitHub (Nov 14, 2022).
FindClosestBlockincorrectly returnsLinkReferenceDefinitionGroupwhen:AutoIdentifierExtensionis active and provides theLinkReferenceDefinitionGroupMarkdownDocument.FindClosestBlock()passing in line number of "Second list item" - hoping to get the secondListItemBlockExample document, parsed with
Markdig 0.30.4Associated
MarkdownDocumenthas the following items at the end of theblockscollection:MarkdownDocument.FindClosestBlock()incorrectly determines that the closest block isLinkReferenceDefinitionGroup, because it happens to be the last item in theblocks.LinkReferenceDefinitionGroupshould not be returned as it does not even exist in the actual document:LinkReferenceDefinitionGroup.Spanis{0 - -1}, itIsEmptyand it'sLineis0.This issue doesn't happen if I call
MarkdownDocument.FindClosestBlock()passing in line number of "First list item" which directly matches theListBlock, or if I type underneath the list, which placesParagraphBlockunderneathListBlock, and prevents the binary search from stumbling uponLinkReferenceDefinitionGroup.@AmadeusW commented on GitHub (Nov 14, 2022):
What are your thoughts on the fix?
Excluding the zero-length
ListReferenceDefinitionGroupfrom Document's children seems more appropriate than special-casing the binary search inFindClosestBlockto ignore empty elements. I'm not sure what would be the side effects of removing theListReferenceDefinitnionGroupfrom Document's children, though.@xoofx commented on GitHub (Nov 18, 2022):
Afair,
ListReferenceDefinitnionGroupis an internal (and not visible) block that keeps track of link definitions. I guess, you can probably remove it after the document has been parsed.It could be also special cased in the
FindClosestBlockby fixingvar upperIndex = blocks.Count - 1;if the last block isListReferenceDefinitnionGroup. But all of this is very old to me, so all I'm saying here might be completely irrelevant! 😅