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

new test wrap preserve link #331

Closed
wants to merge 2 commits into from
Closed

new test wrap preserve link #331

wants to merge 2 commits into from

Conversation

jnnnnn
Copy link

@jnnnnn jnnnnn commented Jul 17, 2023

This is a failing test for an issue I encountered: links with spaces in the link text get broken up and don't render correctly thereafter.

I've spent a few minutes but I can't see an obvious fix. I think parsing the link as a separate node and disabling wrap on the node is probably the way to go but I'd appreciate a pointer into the code for where to change this.

Thanks for looking and for a really fast Markdown formatter!

@kivikakk
Copy link
Owner

Thanks for this very clear report, I appreciate it!

I'm a little unsure what the best thing to do is, here. Our behaviour (intentionally) matches upstream cmark-gfm's exactly:

$ echo 'This is [a link containing spaces that should not be wrapped](https://example.com) and then the text continues after.' | cmark-gfm -t commonmark --width 20
This is [a link
containing spaces
that should not be
wrapped](https://example.com)
and then the text
continues after.
$

Indeed, it's the same in the reference CommonMark implementation, cmark. While I do think this reduces its usefulness for round-tripping, it's not immediately clear if we should diverge from their behaviour, at least by default.

Changes would happen in comrak::cm; searching for render.width shows you various places where the option is honoured. Your desired output would need us to disable wrapping so long as there's a link node somewhere in the current output ancestor chain.

An even nicer version of this would wrap at the start of the link if the link was going to wrap otherwise. i.e.:

 12345678901234567890
-This is [a link
-containing
+This is
+[a link containing
 spaces](https://example.com).

@kivikakk
Copy link
Owner

Hm, actually, I didn't test the main thing: the assertion that it doesn't render correctly thereafter:

$ set INPUT 'This is [a link containing spaces that should not be wrapped](https://example.com) and then the text continues after.'
$ echo $INPUT
This is [a link containing spaces that should not be wrapped](https://example.com) and then the text continues after.
$ echo $INPUT | comrak -t commonmark --width 20
This is [a link
containing spaces
that should not be
wrapped](https://example.com)
and then the text
continues after.
$ echo $INPUT | comrak -t commonmark --width 20 | comrak
<p>This is <a href="https://example.com">a link
containing spaces
that should not be
wrapped</a>
and then the text
continues after.</p>
$

It appears to parse correctly regardless. Can you clarify?

@jnnnnn
Copy link
Author

jnnnnn commented Aug 29, 2023

Ah, it's just the VSCode markdown highlighter that doesn't highlight correctly.

image

@jnnnnn jnnnnn closed this Aug 29, 2023
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

Successfully merging this pull request may close these issues.

2 participants