yuin / goldmark

:trophy: A markdown parser written in Go. Easy to extend, standard(CommonMark) compliant, well structured.
MIT License
3.68k stars 255 forks source link

Allow inline links with empty link text #101

Closed jsteuer closed 4 years ago

jsteuer commented 4 years ago
  1. What version of goldmark are you using? : v1.1.22

  2. What version of Go are you using? : 1.13.7

  3. What operating system and processor architecture are you using? : linux/amd64

  4. What did you do? :

    I need to process links with emtpy link text - for example [](./target.md). My usecase is to write an extension which find the heading of the referenced document and set it as the link text, if its empty.

    package main
    
    import (
        "bytes"
    
        "github.com/yuin/goldmark"
    )
    
    func main() {
        var source = []byte(`[](./target.md)`)
        var buf bytes.Buffer
        if err := goldmark.Convert(source, &buf); err != nil {
            panic(err)
        }
        print(buf.String())
    }
  5. What did you expect to see? :

    <p><a href="./target.md"></a></p>

    Note: I need the corresponding Node in the AST

  6. What did you see instead? :

    <p>[](./target.md)</p>

  7. Did you confirm your output is different from CommonMark online demo or other official renderer correspond with an extension?:

    Yes, the CommonMark specification (https://spec.commonmark.org/0.29/#link-text) says:

    A link text consists of a sequence of zero or more inline elements enclosed by square brackets ([ and ]).

    But there is no example for such a edge case. Issue is created: https://github.com/commonmark/commonmark-spec/issues/636

    Input (the last one is really useless but conform with the specification)

    [My Target](./target.md)
    [](./target.md)
    []()

    CommonMark online demo ([Quick Link](https://spec.commonmark.org/dingus/?text=%5BMy%20Target%5D(.%2Ftarget.md)%0A%5B%5D(.%2Ftarget.md)%0A%5B%5D()%0A)) output

    <p><a href="./target.md">My Target</a>
    <a href="./target.md"></a>
    <a href=""></a></p>

    Goldmark output

    <p><a href="./target.md">My Target</a>
    [](./target.md)
    []()</p>