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

Shorthand link references not recognized when there's whitespace between [] #39

Closed
4 tasks done
nzakas opened this issue Aug 12, 2024 · 8 comments
Closed
4 tasks done
Labels
🙅 no/wontfix This is not (enough of) an issue for this project 👎 phase/no Post cannot or will not be acted on

Comments

@nzakas
Copy link

nzakas commented Aug 12, 2024

Initial checklist

Affected packages and versions

mdast-util-from-markdown@2.0.1

Link to runnable example

https://stackblitz.com/edit/stackblitz-starters-ifpvft?file=index.js

Steps to reproduce

  1. Create a link reference with whitespace in between the []:
[foo][ ]

[foo]: https://example.com
  1. Pass into fromMarkdown()

Expected behavior

The returned AST should identify [foo][ ] as a linkReference. (It appears that GitHub does this. I'm unsure if that's standard behavior for Markdown or not. The Micromark GFM extension exhibits the same behavior.)

Actual behavior

The returned AST identifies [foo][ ] as text rather than a link reference.

Affected runtime and version

node@20.13.0

Affected package manager and version

No response

Affected OS and version

No response

Build and bundle tools

No response

@github-actions github-actions bot added 👋 phase/new Post is being triaged automatically 🤞 phase/open Post is being triaged manually and removed 👋 phase/new Post is being triaged automatically labels Aug 12, 2024
@ChristianMurphy
Copy link
Member

Hey @nzakas! 👋
Commonmark specifies that spaces are significant and it would not match
https://spec.commonmark.org/dingus/?text=%5Bfoo%5D%5B%20%5D%0A%0A%5Bfoo%5D%3A%20https%3A%2F%2Fexample.com

I don't see any spec changes in https://github.github.com/gfm/#link-reference-definitions to reference links
This may be a bug in https://github.com/github/cmark-gfm

@wooorm
Copy link
Member

wooorm commented Aug 13, 2024

This seems to be commonmark/commonmark-spec#653, which shows that most tools work differently than the spec.

I think the spec is currently saying that this is not allowed:

  • what you post could be a shortcut reference, but then it would leave the [ ] in the resulting HTML, which is also not what you expected
  • what you post cannot be a collapsed reference, “followed by the string []”, which this is not

I do consider this to be something that can improved in CM.

But I also consider this a current bug in GFM, which says it sticks to CM, so I don’t feel good about “solving” it in micromark-extension-gfm.

@nzakas
Copy link
Author

nzakas commented Aug 13, 2024

To make sure I'm following, it sounds like you're saying that the spec disallows this behavior, so this is a bug in GitHub's Markdown parser?

@wooorm
Copy link
Member

wooorm commented Aug 13, 2024

Correct

@fasttime
Copy link

I think that in this example, spaces and line breaks are not significant:

[foo][
  bar ]

[bar
]: https://example.com

https://spec.commonmark.org/dingus/?text=%5Bfoo%5D%5B%20%5D%0A%0A%5Bfoo%5D%3A%20https%3A%2F%2Fexample.com

But they are significant if there are only spacing characters?

@wooorm
Copy link
Member

wooorm commented Aug 15, 2024

Correct. There’s indeed a “gap” between the different shortcut links and how they are defined in CM. Shortcut ([x]), collapsed ([x][]), vs. full ([x][y]). Making nzakas’s case ambiguous/vague/weird.

@wooorm
Copy link
Member

wooorm commented Sep 27, 2024

Closing as behavior is intentional, I believe according to spec!

@wooorm wooorm closed this as not planned Won't fix, can't repro, duplicate, stale Sep 27, 2024
@wooorm wooorm added the 🙅 no/wontfix This is not (enough of) an issue for this project label Sep 27, 2024

This comment has been minimized.

@github-actions github-actions bot added 👎 phase/no Post cannot or will not be acted on and removed 🤞 phase/open Post is being triaged manually labels Sep 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🙅 no/wontfix This is not (enough of) an issue for this project 👎 phase/no Post cannot or will not be acted on
Development

No branches or pull requests

4 participants