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

Markdown links with spaces #112

Open
rdnlsmith opened this issue Oct 5, 2018 · 5 comments
Open

Markdown links with spaces #112

rdnlsmith opened this issue Oct 5, 2018 · 5 comments

Comments

@rdnlsmith
Copy link

First off, this is a fantastic extension. I write a lot of Markdown, and the auto-wrap feature makes it a really nice experience!

The one problem I have is with links that have spaces in the link text. If a link is at the end of a line (or has a very long URL) and there are no spaces, it correctly moves the link to the next line:

words words words words [text](http://this.is/a/link)

becomes

words words words words
[text](http://this.is/a/link)

But, if there is a space in the link text, it wraps at the space, breaking the link:

words words words words [link text](http://this.is/a/link)

becomes

words words words words [link
text](http://this.is/a/link)

I often get around this by placing links on their own line within the paragraph, but if the URL is long enough to go past the wrap boundary, it will be auto-wrapped as soon as I press enter.

It would be great if Rewrap could support this! I'd be glad to attempt a PR if you'd like.

@stkb
Copy link
Owner

stkb commented Feb 7, 2022

To anyone still interested in this, what markdown platform/flavor are you using where a newline in the link text breaks the link?

I thought about making it so that [all spaces within a link] would be made non-breaking, but then the end result isn't really pleasing either, since you then have one very long line with link text and the URL.

How I now work around this is by putting a space either before the closing "]" for the text or after the opening "(" for the URL. This gives the best result for me.

@rdnlsmith
Copy link
Author

I just use VS Code's built-in markdown editor, along with extensions mjbvz/vscode-github-markdown-preview-style and yzane/vscode-markdown-pdf. Looking at it now, the resulting link does still work in both outputs, as well as the built-in VS Code markdown preview. I don't remember anymore whether that was the case when I filed the issue. However, wrapping in the middle of the link text does break VS Code's syntax highlighting for the link.

I thought about making it so that [all spaces within a link] would be made non-breaking, but then the end result isn't really pleasing either, since you then have one very long line with link text and the URL.

Yeah, I could see someone preferring it either way. I typically have fairly short link text even when there are spaces involved, so if the URL is long enough that it forces the line to wrap then the line with the URL is going to be pretty long regardless, and the link text doesn't make much difference.

It might be nice to have a setting for whether to treat spaces in link text as breaking or non-breaking. I would still be willing to attempt a PR if you agree with this.

@stkb
Copy link
Owner

stkb commented Feb 7, 2022

@rdnlsmith Thanks for the offer but the code is in a really messy and volatile state right now while I'm rewriting lots of stuff.

I do plan to add a feature, where users can add find/replace operations that are performed at the same time as wrapping, and that will let anyone experiment with converting spaces in links to non-breaking (which I'm still not sure is a good idea).

@Garbaz
Copy link

Garbaz commented Jun 18, 2024

Any status update on this?

Regarding where this is an issue:

Very minor, but the highlighting in Markdown documents breaks partially:

image
^ How it is supposed to look

image
^ How it looks with broken link text (missing underline)

More importantly, links aren't rendered correctly in VSCode's hover widget:

image
^ When the link text is unbroken in the Python doc string

image
^ When the link text is broken due to Rewrap

@jotabe-net
Copy link

jotabe-net commented Dec 3, 2024

I don't know which tool you are using, but the widely accepted CommonMark specs allow the line breaks inside the linkt tile:

Although link titles may span multiple lines, they may not contain a blank line.

So, IMO, this is not a bug.

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

No branches or pull requests

4 participants