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

Links that wrap lines render as separate links for each line #222

Closed heaths closed 3 years ago

heaths commented 3 years ago

In the GitHub CLI, there are several commands that show links as shown in the repro below. If these links span new lines, the link parts are rendered as separate links:

With the GitHub CLI installed:

script
gh pr -R cli/cli view 3519 --comments
exit

If you look in the file for "image", you'll find a link like so:

52: ^[[38;5;243m^[[0m^[[38;5;243m^[[0m  ^[[38;5;243mImage: image →^[[0m^[[38;5;252m ^[[0m^[[38;5;212;4mhttps://user-images.githubusercontent.com/1532486/116502954-^[[38;5;252m ^[[0m^[[0m^M
53: ^[[0m^[[38;5;212;4m^[[0m  ^[[38;5;212;4mc3815e80-a869-11eb-8da8-51592e7d2ba6.png^[[0m^[[38;5;252m

Line 53 is truncated, but you can see how the URL https://user-images.githubusercontent.com/1532486/116502954-c3815e80-a869-11eb-8da8-51592e7d2ba6.png is wrapped. Terminals that automatically detect URLs will fail to open these links correctly - or at least as desired. In this case, it 404s because the detect link is only https://user-images.githubusercontent.com/1532486/116502954.

Alternatively, you could add OSC 8 (perhaps even optionally) sequences to explicit mark the link, as described here.

  1. What version of goldmark are you using? : 1.3.3
  2. What version of Go are you using? : 1.16.3
  3. What operating system and processor architecture are you using? : Ubuntu 18.04 on WSL2 using Windows Terminal 1.8
  4. What did you do? : Ran gh pr -R cli/cli view 3519 --comments as in repro above.
  5. What did you expect to see? : a link from markdown I could click on
  6. What did you see instead? : a link that resulted in a 404 when clicked
  7. Did you confirm your output is different from CommonMark online demo or other official renderer correspond with an extension?: Not actually a markdown rendering issue, per se. Your coloring was correct, but the detected link in Windows Terminal (other terms detect links as well) resulted in a 404 was it spanned lines. This is more of a feature request, really.
yuin commented 3 years ago

This is a goldmark repository. I do not know about cli/cli. Your report is completely about cli/cli.

heaths commented 3 years ago

The cli uses your module to do the markdown rendering. I used the CLI only as a repro. This is a request to use the OSC 8 sequence to explicitly wrap links when rendering.

heaths commented 3 years ago

Digging into this more, I see that charmbracelet/glamour is doing the actual rendering, and there is already a bug tracking this.