Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linkify regression #70

Closed
bep opened this issue Dec 20, 2019 · 4 comments
Closed

Linkify regression #70

bep opened this issue Dec 20, 2019 · 4 comments
Labels
bug Something isn't working

Comments

@bep
Copy link

bep commented Dec 20, 2019

package main

import (
	"bytes"
	"fmt"
	"log"

	"github.com/yuin/goldmark"
	"github.com/yuin/goldmark/extension"
)

func main() {

	markdown := goldmark.New(
		goldmark.WithExtensions(extension.Linkify),
	)
	var buf bytes.Buffer
	err := markdown.Convert([]byte(`[https://google.com](https://google.com)`), &buf)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(buf.String())
}

Produces

<p>[<a href="https://google.com%5D(https://google.com)">https://google.com](https://google.com)</a></p>

gohugoio/hugo#6649

@yuin yuin closed this as completed in 12851a0 Dec 22, 2019
@zzwx
Copy link
Contributor

zzwx commented Dec 22, 2019

Confirming 12851a0 renders

[https://golang.org/](https://golang.org) as

<a href="https://golang.org">https://golang.org/</a>

[https://golang.org](https://golang.org) as

<a href="https://golang.org">https://golang.org</a>

[https://golang.org](https://golang.org/)

<a href="https://golang.org/">https://golang.org</a>

[https://golang.org/](https://golang.org/)

<a href="https://golang.org/">https://golang.org/</a>

@yuin
Copy link
Owner

yuin commented Dec 22, 2019

@bep
@zzwx

As I wrote in #74, I think this is also an undefined and ambiguous behavior about GFM.
I do not agree with 'defined by program works' ( to avoid this, commonmark spec was defined).

But there was nothing else to do, so I've changed goldmark to closer to GFM implementation .

Instead of resolving this issue, you will see other strange rendering in GFM.

[ a b http://www.google.com

is not autolinked now(You can try this in github comment editor)

Do you think this is a correct behavior? Can you explain why this is not autolinked?

This is why I do not agree with 'defined by program works'. Behavior should be defined by specifications.

@bep
Copy link
Author

bep commented Dec 22, 2019

@yuin I agree with you about the specification part. But in this case, the specification is obviously missing some important bits to handle the ambiguity introduced by GFM. That is unfortunate as everyone who implements this has had to have this discussion.

To me, this is a simple as:

  • The examples I've seen in these issues looks obviously wrong.
  • I would say that, for auto-linking, it is much better to not link when in doubt, as that gives the user an option to manually link if needed.

@yuin
Copy link
Owner

yuin commented Dec 22, 2019

@bep, Yes you are right.

[ a b http://www.google.com

is not autolinked also looks obviously wrong.(But GFM works like it)

I would say that, for auto-linking, it is much better to not link when in doubt, as that gives the user an option to manually link if needed.

CommonMark defines that autolink should be surrounded with '<' '>' . So I think GFM autolink should be more defensive. GFM autolink parses URL aggressively(including most punctuations). This causes many problems like above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants