xoofx / xoofx/markdig

No easy access to label for links that use reference links

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

Nobody has claimed this yet.

bug PR Welcome!
Dominant language
C#
Stars
5.3k
Forks
510
Avg merge
8d 5h
Merged PRs (30d)
5

Description

When working with inline links, the behavior of the LabelSpan property seems to be inconsistent between inline links that use reference links and those that do not.

This is best demonstrated with an example.

Suppose we're parsing the following Markdown

[Link using reference][valid-file]
[Link without reference](/valid-file-link.md)

[valid-file]: ./valid-file-link.md

using the following code:

var pipeline = MarkdownPipelineBuilder().UsePreciseSourceLocation().Build();
var markdownDocument = Markdown.Parse(markdown, pipeline);

Then if I use the Span, LabelSpan and UrlSpan properties to output the corresponding Markdown in the document, I get the following:

First link (using the reference link):

  • Span: "[Link using reference][valid-file]"
  • LabelSpan: "valid-file"
  • UrlSpan: "./valid-file-link.md"

Second link (not using the reference link):

  • Span: "[Link without reference](/valid-file-link.md)"
  • LabelSpan: "Link without reference"
  • UrlSpan: "/valid-file-link.md"

I would have expected the LabelSpan property of the first link to return Link using reference, not valid-file.

Am I doing something wrong or is this expected behavior?

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 with MarkdownPipelineBuilder.UsePreciseSourceLocation and Markdown.Parse using the supplied reference-link example, then inspect how Span, LabelSpan, and UrlSpan are assigned for each link. Done means the reference-link LabelSpan identifies "Link using reference" consistently with the inline link while UrlSpan remains "./valid-file-link.md", with the behavior covered by a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, markdown
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.