JuliaLang / julia

The Julia Programming Language
https://julialang.org/
MIT License
45.44k stars 5.46k forks source link

markdown parser doesn't recognize link reference definitions #19844

Open stevengj opened 7 years ago

stevengj commented 7 years ago

The Markdown parser does not seem to recognize link reference definitions, unlike inline links:

julia> using Base.Markdown

julia> md"""
       a [link] here and an [inline link](http://fake.url)

       [link]: http://fake.url
       """
  a [link] here and an inline link

  [link]: http://fake.url

julia> dump(ans)
Base.Markdown.MD
  content: Array{Any}((2,))
    1: Base.Markdown.Paragraph
      content: Array{Any}((2,))
        1: String "a [link] here and an "
        2: Base.Markdown.Link
          text: Array{Any}((1,))
            1: String "inline link"
          url: String "http://fake.url"
    2: Base.Markdown.Paragraph
      content: Array{Any}((1,))
        1: String "[link]: http://fake.url"
...

(See e.g. JuliaLang/IJulia.jl#493 for where this came up.)

mpastell commented 7 years ago

Julia Markdown doesn't follow the CommonMark spec. According to docs (http://docs.julialang.org/en/release-0.5/manual/documentation/#markdown-syntax) Julia has footnote references using[^link] syntax:

julia> md"""
       a [^link] here and an [inline link](http://fake.url)
       [^link]: http://fake.url
       """.content
1-element Array{Any,1}:
 Base.Markdown.Paragraph(Any["a ",Base.Markdown.Footnote("link",nothing)," here and an ",Base.Markdown.Link(Any["inline link"],"http://fake.url")," ",Base.Markdown.Footnote("link",nothing),": http://fake.url"])
mpastell commented 7 years ago

It would be nice to add link reference definitions as well. I see pandoc has both footnotes and link references.

MichaelHatherly commented 7 years ago

Yes, would be nice to have. We should try follow CommonMark where possible/appropriate, though there have been some features that we needed that just haven't been standardised in CM yet (tables, I think is one of them).

@mpastell, are you planning on working on this?

mpastell commented 7 years ago

Not at the moment, I will see if I find the time to do it.

Looks like it shouldn't be too difficult to add this to the parser by modifying the footnote code, but I haven't looked into what needs to be done with the writers.

adigitoleo commented 2 years ago

This would be really great. It's a lot easier to maintain a list of reference links than wade through long markdown files (e.g. docs) to update potentially duplicated inline links.