markdig
markdig copied to clipboard
LinkReferenceDefinition source position is ignored in NormalizeRenderer
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
Can you explain what fails exactly?
when without use advanced, left side is normed, right side is source.

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.
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
left side is normed, right side is source.

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.
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!~~
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.
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.
yes, the NormalizeRenderer is inverse of parser. it can help to test the parser if respect raw text. so hope to develop consistly.