LinkReferenceDefinition source position is ignored in NormalizeRenderer #286

Open
opened 2026-01-29 14:32:47 +00:00 by claunia · 10 comments
Owner

Originally created by @xp44mm on GitHub (Mar 27, 2019).

the test is follow:

type MarkdigTest(output: ITestOutputHelper) =
    let text =
        Path.Combine(@"C:\Program Files\Typora\resources\app\Docs","Markdown Reference.md")
        |> File.ReadAllText

    let document =
        Markdown.Parse(text, MarkdownPipelineBuilder().UseAdvancedExtensions().Build())

    [<Fact>]
    member this.``NormalizeRenderer Test``() =
        use writer = new StringWriter()
        let normalizer = new NormalizeRenderer(writer)
        normalizer.Render(document) |> ignore
        let raw = writer.ToString()
        File.WriteAllText(@"d:\Markdown Reference.md",raw)

the test file is, need remove the .txt extent name:
Markdown Reference.md.txt

please note that Footnotes, Reference Links, URLs, this is normalized file:
Markdown Reference.md.txt

Originally created by @xp44mm on GitHub (Mar 27, 2019). the test is follow: ```F# type MarkdigTest(output: ITestOutputHelper) = let text = Path.Combine(@"C:\Program Files\Typora\resources\app\Docs","Markdown Reference.md") |> File.ReadAllText let document = Markdown.Parse(text, MarkdownPipelineBuilder().UseAdvancedExtensions().Build()) [<Fact>] member this.``NormalizeRenderer Test``() = use writer = new StringWriter() let normalizer = new NormalizeRenderer(writer) normalizer.Render(document) |> ignore let raw = writer.ToString() File.WriteAllText(@"d:\Markdown Reference.md",raw) ``` the test file is, need remove the .txt extent name: [Markdown Reference.md.txt](https://github.com/lunet-io/markdig/files/3011949/Markdown.Reference.md.txt) please note that Footnotes, Reference Links, URLs, this is normalized file: [Markdown Reference.md.txt](https://github.com/lunet-io/markdig/files/3012080/Markdown.Reference.md.txt)
claunia added the bugPR Welcome! labels 2026-01-29 14:32:48 +00:00
Author
Owner

@xoofx commented on GitHub (Mar 27, 2019):

Can you explain what fails exactly?

@xoofx commented on GitHub (Mar 27, 2019): Can you explain what fails exactly?
Author
Owner

@xp44mm commented on GitHub (Mar 27, 2019):

when without use advanced, left side is normed, right side is source.
result

@xp44mm commented on GitHub (Mar 27, 2019): when without use advanced, left side is normed, right side is source. ![result](https://user-images.githubusercontent.com/10087796/55062114-3d095a00-50b0-11e9-8e83-150fd63da7a8.gif)
Author
Owner

@xp44mm commented on GitHub (Mar 27, 2019):

i remove some config:

    let document =
        let pipeline =
            MarkdownPipelineBuilder()//.UseAdvancedExtensions()
                .UseAbbreviations()
                //.UseAutoIdentifiers() //* append lot of `[]:` space lines.
                .UseCitations()
                .UseCustomContainers()
                .UseDefinitionLists()
                .UseEmphasisExtras()
                .UseFigures()
                .UseFooters()
                //.UseFootnotes() //* the `[^xxx]` in parag lost, the remark mismatch and occur at article bottom.
                .UseGridTables()
                .UseMathematics()
                .UseMediaLinks()
                .UsePipeTables()
                .UseListExtras()
                .UseTaskLists()
                .UseDiagrams()
                //.UseAutoLinks()//* this is right.
                .UseGenericAttributes()
                .Build()
        Markdown.Parse(text, pipeline)

maybe the link reference definition move all to first occurency together from article bottom.

@xp44mm commented on GitHub (Mar 27, 2019): i remove some config: ```F# let document = let pipeline = MarkdownPipelineBuilder()//.UseAdvancedExtensions() .UseAbbreviations() //.UseAutoIdentifiers() //* append lot of `[]:` space lines. .UseCitations() .UseCustomContainers() .UseDefinitionLists() .UseEmphasisExtras() .UseFigures() .UseFooters() //.UseFootnotes() //* the `[^xxx]` in parag lost, the remark mismatch and occur at article bottom. .UseGridTables() .UseMathematics() .UseMediaLinks() .UsePipeTables() .UseListExtras() .UseTaskLists() .UseDiagrams() //.UseAutoLinks()//* this is right. .UseGenericAttributes() .Build() Markdown.Parse(text, pipeline) ``` maybe the **link reference definition** move all to first occurency together from article bottom.
Author
Owner

@xoofx commented on GitHub (Mar 27, 2019):

Oh, yes, the NormalizeRenderer is by far not compatible with all extensions. It requires still lots of work and I have personally zero spare time left for that. so PR welcome. See also issue #155

@xoofx commented on GitHub (Mar 27, 2019): Oh, yes, the `NormalizeRenderer` is by far not compatible with all extensions. It requires still lots of work and I have personally zero spare time left for that. so PR welcome. See also issue #155
Author
Owner

@xp44mm commented on GitHub (Mar 27, 2019):

left side is normed, right side is source.
result

@xp44mm commented on GitHub (Mar 27, 2019): left side is normed, right side is source. ![result](https://user-images.githubusercontent.com/10087796/55063927-02092580-50b4-11e9-901c-9deefa684138.gif)
Author
Owner

@xoofx commented on GitHub (Mar 27, 2019):

as I said, it is a known issue, look at #155 and you will see that most extensions are not supported by normalize, and even the core part of CommonMark might not be entirely supported well.

@xoofx commented on GitHub (Mar 27, 2019): as I said, it is a known issue, look at #155 and you will see that most extensions are not supported by normalize, and even the core part of CommonMark might not be entirely supported well.
Author
Owner

@xp44mm commented on GitHub (Mar 27, 2019):

hello! i read the code, i guess the bug not in normalize, insteed, bug in parser. i use regex and f# , C# i just read can't write. manapulate char and use ref to modify source code beyond my job.

allow more than one LinkReferenceDefinitionGroup in a doc. for example, there is a gourp per every section, and a doc has many sections. next code seem expression one group in a document. that will merged all groups into first. no respect source.
354db6b306/src/Markdig/Syntax/LinkReferenceDefinitionExtensions.cs (L48)

i think the action of LinkReferenceDefinitionGroup semilar to QuoteBlocks, continuous LinkReferenceDefinition is a group, interval other block's LinkReferenceDefinition belong another group. actually, i think LinkReferenceDefinition don't need be pushed into group, they can seperate beings just like common paragraph.

you let it unique in a doc is for building association between title and link definition. but i think latter not so nessassary to add complex. i still think that computer can auto link source to target is a super cool action!

@xp44mm commented on GitHub (Mar 27, 2019): hello! i read the code, i guess the bug not in normalize, insteed, bug in parser. i use regex and f# , C# i just read can't write. manapulate char and use ref to modify source code beyond my job. allow more than one `LinkReferenceDefinitionGroup` in a doc. for example, there is a gourp per every section, and a doc has many sections. next code seem expression one group in a document. that will merged all groups into first. no respect source. https://github.com/lunet-io/markdig/blob/354db6b306559b73825140b33c3634137be062b1/src/Markdig/Syntax/LinkReferenceDefinitionExtensions.cs#L48 i think the action of `LinkReferenceDefinitionGroup` semilar to `QuoteBlocks`, continuous `LinkReferenceDefinition` is a group, interval other block's `LinkReferenceDefinition` belong another group. actually, i think `LinkReferenceDefinition` don't need be pushed into group, they can seperate beings just like common paragraph. ~~you let it unique in a doc is for building association between title and link definition. but i think latter not so nessassary to add complex. i still think that computer can auto link source to target is a super cool action!~~
Author
Owner

@MihaZupan commented on GitHub (Mar 27, 2019):

Yes, the approach with a single LinkReferenceDefinitionGroup would have to be changed for the NormalizeRenderer. For the HtmlRenderer it was okay since the location of the definition does not matter for the overall document.

@MihaZupan commented on GitHub (Mar 27, 2019): Yes, the approach with a single `LinkReferenceDefinitionGroup` would have to be changed for the `NormalizeRenderer`. For the `HtmlRenderer` it was okay since the location of the definition does not matter for the overall document.
Author
Owner

@xoofx commented on GitHub (Mar 27, 2019):

hello! i read the code, i guess the bug not in normalize, insteed, bug in parser. i use regex and f# , C# i just read can't write. manapulate char and use ref to modify source code beyond my job.

Yeah, as @MihaZupan suggested, originally markdig was mainly and only developed for HTML rendering. NormalizeRenderer has been added later, but is far from completed, and it will probably never be completed if nobody in the markdig userbase is willing to contribute fixing it. And that's lots of work.

@xoofx commented on GitHub (Mar 27, 2019): > hello! i read the code, i guess the bug not in normalize, insteed, bug in parser. i use regex and f# , C# i just read can't write. manapulate char and use ref to modify source code beyond my job. Yeah, as @MihaZupan suggested, originally markdig was mainly and only developed for HTML rendering. NormalizeRenderer has been added later, but is far from completed, and it will probably never be completed if nobody in the markdig userbase is willing to contribute fixing it. And that's lots of work.
Author
Owner

@xp44mm commented on GitHub (Mar 27, 2019):

yes, the NormalizeRenderer is inverse of parser. it can help to test the parser if respect raw text. so hope to develop consistly.

@xp44mm commented on GitHub (Mar 27, 2019): yes, the NormalizeRenderer is inverse of parser. it can help to test the parser if respect raw text. so hope to develop consistly.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/markdig#286