FindClosestBlock incorrectly returns LinkReferenceDefinitionGroup
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 5.3k
- Forks
- 510
- Avg merge
- 8d 5h
- Merged PRs (30d)
- 5
Description
FindClosestBlock incorrectly returns LinkReferenceDefinitionGroup when:
- Markdown document ends with a list,
AutoIdentifierExtensionis active and provides theLinkReferenceDefinitionGroup- I call
MarkdownDocument.FindClosestBlock()passing in line number of "Second list item" - hoping to get the secondListItemBlock
Example document, parsed with Markdig 0.30.4
Paragraph
- First list item with a [link](target.txt)
- Second list item with a [link](target.txt) <eod>
Associated MarkdownDocument has the following items at the end of the blocks collection:
ParapgraphBlock
ListBlock
LinkReferenceDefinitionGroup
MarkdownDocument.FindClosestBlock() incorrectly determines that the closest block is LinkReferenceDefinitionGroup, because it happens to be the last item in the blocks.
LinkReferenceDefinitionGroup should not be returned as it does not even exist in the actual document: LinkReferenceDefinitionGroup.Span is {0 - -1}, it IsEmpty and it's Line is 0.
This issue doesn't happen if I call MarkdownDocument.FindClosestBlock() passing in line number of "First list item" which directly matches the ListBlock, or if I type underneath the list, which places ParagraphBlock underneath ListBlock, and prevents the binary search from stumbling upon LinkReferenceDefinitionGroup.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at MarkdownDocument.FindClosestBlock and reproduce the example with AutoIdentifierExtension enabled, ending the document with the list. Verify how the empty LinkReferenceDefinitionGroup affects the block search; done means the second list item's line resolves to the ListBlock or ListItemBlock rather than the empty group, while the other described cases still work.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100