Broken handling of link blocks separated by \r\n #456

Closed
opened 2026-01-29 14:37:14 +00:00 by claunia · 2 comments
Owner

Originally created by @ForNeVeR on GitHub (Apr 10, 2021).

The problem

Markdig seems to have a problem parsing the link blocks separated with \r\n. By "link blocks", I mean blocks like this (I usually put them at the end of a section or the whole document):

document document …

[link1]: http://example.com
[link2]: https://example.com

Only one of these links will be currently parsed.

Example code

(used Markdig 0.24.0)

using System;
using Markdig;

namespace ConsoleApp33
{
    class Program
    {
        static void Main(string[] args)
        {
            var text1 = "[Link 1][link-1], [link 2][link-2].\r\n\r\n[link-1]: https://example.com\r\n[link-2]: https://example.com";
            var document1 = Markdown.Parse(text1);
            Console.WriteLine(document1.ToHtml());
            
            var text2 = "[Link 1][link-1], [link 2][link-2].\n\n[link-1]: https://example.com\n[link-2]: https://example.com";
            var document2 = Markdown.Parse(text2);
            Console.WriteLine(document2.ToHtml());
        }
    }
}

I expect two identical sets of output from this code:

<p><a href="https://example.com">Link 1</a>, <a href="https://example.com">link 2</a>.</p>
<p><a href="https://example.com">Link 1</a>, <a href="https://example.com">link 2</a>.</p>

But in reality, the outputs are different:

<p><a href="https://example.com">Link 1</a>, [link 2][link-2].</p>
<p><a href="https://example.com">Link 1</a>, <a href="https://example.com">link 2</a>.</p>
Originally created by @ForNeVeR on GitHub (Apr 10, 2021). ## The problem Markdig seems to have a problem parsing the link blocks separated with `\r\n`. By "link blocks", I mean blocks like this (I usually put them at the end of a section or the whole document): ``` document document … [link1]: http://example.com [link2]: https://example.com ``` Only one of these links will be currently parsed. ## Example code (used Markdig 0.24.0) ```csharp using System; using Markdig; namespace ConsoleApp33 { class Program { static void Main(string[] args) { var text1 = "[Link 1][link-1], [link 2][link-2].\r\n\r\n[link-1]: https://example.com\r\n[link-2]: https://example.com"; var document1 = Markdown.Parse(text1); Console.WriteLine(document1.ToHtml()); var text2 = "[Link 1][link-1], [link 2][link-2].\n\n[link-1]: https://example.com\n[link-2]: https://example.com"; var document2 = Markdown.Parse(text2); Console.WriteLine(document2.ToHtml()); } } } ``` I expect two identical sets of output from this code: ```html <p><a href="https://example.com">Link 1</a>, <a href="https://example.com">link 2</a>.</p> <p><a href="https://example.com">Link 1</a>, <a href="https://example.com">link 2</a>.</p> ``` But in reality, the outputs are different: ```html <p><a href="https://example.com">Link 1</a>, [link 2][link-2].</p> <p><a href="https://example.com">Link 1</a>, <a href="https://example.com">link 2</a>.</p> ```
claunia added the bug label 2026-01-29 14:37:14 +00:00
Author
Owner

@MihaZupan commented on GitHub (Apr 10, 2021):

Looks like a regression from #481. cc @generateui

@ForNeVeR I would suggest switching from 0.24 to 0.23 that doesn't have these issues.

I'll try to look into what's happening here this weekend.

@MihaZupan commented on GitHub (Apr 10, 2021): Looks like a regression from #481. cc @generateui @ForNeVeR I would suggest switching from 0.24 to 0.23 that doesn't have these issues. I'll try to look into what's happening here this weekend.
Author
Owner

@xoofx commented on GitHub (Jun 10, 2021):

This should be fixed by 4c92fe5 and available in up-coming 0.25.0
I just started to have a look this morning and it took quite a bit of time to dig into this bug. Trivias handling is definitely complicating the code and its debugging.

@xoofx commented on GitHub (Jun 10, 2021): This should be fixed by 4c92fe5 and available in up-coming 0.25.0 I just started to have a look this morning and it took quite a bit of time to dig into this bug. Trivias handling is definitely complicating the code and its debugging.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/markdig#456