xoofx / xoofx/markdig

FindClosestBlock incorrectly returns LinkReferenceDefinitionGroup

Open
#677 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

question
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,
  • AutoIdentifierExtension is active and provides the LinkReferenceDefinitionGroup
  • I call MarkdownDocument.FindClosestBlock() passing in line number of "Second list item" - hoping to get the second ListItemBlock

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.