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

Wrapped links are invalid #36

Closed
EricAndrechek opened this issue May 16, 2022 · 8 comments
Closed

Wrapped links are invalid #36

EricAndrechek opened this issue May 16, 2022 · 8 comments
Labels

Comments

@EricAndrechek
Copy link

Hi! When my terminal width is too narrow, text automatically wraps which ends up breaking long links. Below is a screenshot:
image

This means that only the first line of the hyperlink is active: https://github.com/ValveSoftware/steam-for- which gives a 404, obviously. I have attempted to read through glow's documentation and issues for anyone referencing this issue but have found no such mention of it.

Additionally, I notice that with glow, the markdown fails to make the text an actual hyperlink, instead just coloring it and underlining it.

Using escape sequences, it is possible to do this in terminal:
image

This acts as a valid hyperlink, and is additionally immune to this sort of text wrapping issue, as demonstrated here:
image

Not sure if this would best be solved with code changes to this repo, or if this may be better targeted towards glow.

Thanks!

@EricAndrechek
Copy link
Author

EricAndrechek commented May 16, 2022

I have created an issue within the glow repository after doing some additional testing. It appears to be a bug within glow, not this program. The solution I have proposed here and in the glow issue should resolve things. If glow takes too long to fix this, it could potentially be implemented as a hacky fix within this program until glow fixes it on their end.

@b3nj5m1n
Copy link
Owner

This is definitely an issue with glow.

I don't think I want to implement a fix here, it's outside the scope of this project. I'll keep up with the issue in glow.

If you can find a maintainable solution for this repo, I'd be more than happy to look at a PR, though.

Thank you for bringing this to my attention.

@b3nj5m1n
Copy link
Owner

Upon closer inspection, this doesn't seem to be an issue with glow, you should be able to configure this.

You can invoke glow with the -s flag and provide a custom style definition in json, see this page for details. I think using the prefix, suffix, and block_prefix/block_suffix, you should be able to wrap links in this escape sequence.

I'm sceptical about whether we should use that as a default, though, since not many terminal emulators seem to actually support this escape sequence.

Here's the relevant PR for alacritty, for example.

If you're interested, you could see if you manage to create a style definition for this, it shouldn't be that hard, afterwards, we could think about trying to detect that ability, but I don't want to add much complexity to this script, so I can't promise anything about merging such functionality.

@Ballasi
Copy link
Contributor

Ballasi commented May 16, 2022

Isn't this related to the terminal's capability to create links automatically from text?

I cannot reproduce this on alacritty or gnome-terminal. What terminal are you using @EricAndrechek?

@b3nj5m1n
Copy link
Owner

I'm sceptical about whether we should use that as a default, though, since not many terminal emulators seem to actually support this escape sequence.

That's what I was talking about. You can reproduce their issue using kitty though.

@EricAndrechek
Copy link
Author

Upon closer inspection, this doesn't seem to be an issue with glow, you should be able to configure this.

I say it is an issue with glow, as I believe it should do that for you. When I write [a link](https://example.com) in markdown "a link", it creates a hyperlink. I don't have to specify line breaks or anything, it sorts that out for me. If the link wraps to a new line, the whole thing is still valid, it doesn't separate the URL onto two different lines making both lines invalid.

Isn't this related to the terminal's capability to create links automatically from text?

As to this comment, I don't believe so, no. In my testing with gnome-terminal, running

echo "https://example.com/really-long-link-to-test-a-line-break-that-is-well-over-the-default-80-character-line-length-to-force-the-terminal-to-automatically-wrap-this-text"

will automatically wrap as handled by the terminal, and is still a valid and clickable link, as shown below.

image

Glow/glamour handles rendering the markdown differently than expected, however. The markdown is not turned into a hyperlink within the terminal, which I understand as it means that even if your terminal doesn't support the special hyperlink escape sequences it can still identify the full link to automatically turn it into a clickable link, or allow you to copy and paste it into a web browser. Here is an illustration of the differences I am talking about:
image

IMO, the first hyperlink option is easily the cleanest, but I understand that it may not work on every terminal. The second option clearly works as an alternative, which is fine. The problem arises with the third method. Glow identifies that the terminal width is 80 and manually tells the text to wrap, instead of letting the terminal handle it. This breaks the link. If I tell glow to ignore the terminal width and use a wrap length longer than the link, the terminal wraps it automatically and the link still works.

@EricAndrechek
Copy link
Author

Ok - follow up here. I attempted to using the styling json for glamour/glow to make the hyperlinking work, but unfortunately the order glamour puts them in is incorrect for what the hyperlink expects, and without making modifications to glow this seems impossible. My json was as follows:

{
    "link": {
        "block_prefix": "\\033\\\\",
        "block_suffix": "\\033]8;;\\033\\\\\n"
    },
    "link_text": {
        "block_prefix": "\\033]8;;"
    }
}

But unfortunately, glow doesn't actually listen to the escape sequences:
image

Wrapping the whole thing inside an echo will have it listen to the escape sequences and render correctly:
image

But as you can see, the link and the link_text are flipped. This is not the way the terminal hyperlink expects it. Again, not an easy fix to this other than modifying glamour's code. Luckily, there seem to already be some people aware of this and working on it: Glamour: Feature: Support 'modern' anchors through ANSI OSC 8 escapes, and Github CLI: Auto-detected links with new lines result in 404s when clicked

@b3nj5m1n
Copy link
Owner

Thanks for your research!

As it's not an issue with this project, I'll close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants