go-term-markdown icon indicating copy to clipboard operation
go-term-markdown copied to clipboard

Link text disappears if it contains inline code in it

Open KEINOS opened this issue 6 years ago • 3 comments

Thank you for providing us such a great, simple, nice and neat app!

It might be against Markdown's syntax rules but I found out that if the link ([]()) contains a word or phrase with enclosed backticks (`) in a "link text", the "link text" disappears.

$ cat sample.md
[`foo` bar](http://sample.com/)

[foo bar](http://sample.com/)

$ mdr sample.md
[](http://sample.com/)

[foo bar](http://sample.com/)

GitHub flavor markdown works tho: foo bar

  • Env info:
    • OS: macOS 10.14.6 (OSX Mojave), mdr: mdr_darwin_amd64 v0.2.1, CPU: Intel Core i5
    • OS: Raspbian 8.0 (Jessie), mdr: mdr_linux_arm v0.2.1, CPU: ARM v6l

KEINOS avatar Jan 03 '20 16:01 KEINOS

I think what happens is that I assumed that the "link text" would be well, a simple ast.Text. It seems that was too much to assume. Relevant code is there: https://github.com/MichaelMure/go-term-markdown/blob/master/renderer.go#L300-L312

Man, Markdown is complex.

MichaelMure avatar Jan 03 '20 16:01 MichaelMure

So I think the fix could be:

  • on entering ast.Link, print [
  • let whatever child node render in r.inlineAccumulator
  • on exiting, print the rest: ](....)

That could get messy though if it's possible to have an image there.

MichaelMure avatar Jan 03 '20 16:01 MichaelMure

Thanks for the quick response!

Man, Markdown is complex.

I agree. Too many flavors.

I'm not a Gopher but thinking of recursive processing ... uh ... I can imagine how tough it would be.

I'm not in a rush. So please take your time. Thank you!

KEINOS avatar Jan 03 '20 16:01 KEINOS