Link reference definitions must be separated by blank lines #513

Closed
opened 2026-01-29 14:38:29 +00:00 by claunia · 1 comment
Owner

Originally created by @jo3w4rd on GitHub (Mar 11, 2022).

The common mark spec (line 3113 or so) states:

Several [link reference definitions]
can occur one after another, without intervening blank lines.

However, when I try this, only the first definition is recognized and used. All subsequent definitions are ignored and their matching link references are not treated as links.

For example:


* [Catalog]
* [Content Update]
* [Build]

[Content Update]: #content-update
[Build]: #build
[Catalog]: #catalog

Is converted into HTML as:

<h1>Look at reference links</h1>
<ul>
<li>[Catalog]</li>
<li><a href="#content-update">Content Update</a></li>
<li>[Build]</li>
</ul>

If I insert a blank line after each definition, the links are constructed properly:

# Look at reference links

* [Catalog]
* [Content Update]
* [Build]

[Content Update]: #content-update

[Build]: #build

[Catalog]: #catalog

---
<h1>Look at reference links</h1>
<ul>
<li><a href="#catalog">Catalog</a></li>
<li><a href="#content-update">Content Update</a></li>
<li><a href="#build">Build</a></li>
</ul>

This appears to be a parsing problem, not an HTML rendering problem. The links are missing in the syntax tree after Markdown.Parse().

Code:

           string filePath = "D:\\Repos\\MarkdownTest.md";
            string markdown = File.ReadAllText(filePath);
            var pipeline = new MarkdownPipelineBuilder().Build();
            MarkdownDocument md = Markdown.Parse(markdown, pipeline);
            Console.WriteLine(md.ToHtml(pipeline));
Originally created by @jo3w4rd on GitHub (Mar 11, 2022). The common mark spec (line 3113 or so) states: ``` Several [link reference definitions] can occur one after another, without intervening blank lines. ``` However, when I try this, only the first definition is recognized and used. All subsequent definitions are ignored and their matching link references are not treated as links. For example: ```# Look at reference links * [Catalog] * [Content Update] * [Build] [Content Update]: #content-update [Build]: #build [Catalog]: #catalog ``` Is converted into HTML as: ``` <h1>Look at reference links</h1> <ul> <li>[Catalog]</li> <li><a href="#content-update">Content Update</a></li> <li>[Build]</li> </ul> ``` If I insert a blank line after each definition, the links are constructed properly: ``` # Look at reference links * [Catalog] * [Content Update] * [Build] [Content Update]: #content-update [Build]: #build [Catalog]: #catalog --- <h1>Look at reference links</h1> <ul> <li><a href="#catalog">Catalog</a></li> <li><a href="#content-update">Content Update</a></li> <li><a href="#build">Build</a></li> </ul> ``` This appears to be a parsing problem, not an HTML rendering problem. The links are missing in the syntax tree after `Markdown.Parse()`. Code: ``` string filePath = "D:\\Repos\\MarkdownTest.md"; string markdown = File.ReadAllText(filePath); var pipeline = new MarkdownPipelineBuilder().Build(); MarkdownDocument md = Markdown.Parse(markdown, pipeline); Console.WriteLine(md.ToHtml(pipeline)); ```
Author
Owner

@jo3w4rd commented on GitHub (Mar 11, 2022):

Whoops, I had left Markdig on an older version after testing the track trivia problem. This has been fixed (sometime between nuget version 24 and 27).

@jo3w4rd commented on GitHub (Mar 11, 2022): Whoops, I had left Markdig on an older version after testing the track trivia problem. This has been fixed (sometime between nuget version 24 and 27).
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/markdig#513