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 footnote validation #100

Open
mail2nnv opened this issue Nov 22, 2022 · 5 comments
Open

Markdown footnote validation #100

mail2nnv opened this issue Nov 22, 2022 · 5 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug
Milestone

Comments

@mail2nnv
Copy link

Does this issue occur when all extensions are disabled?: Yes/No
Yes

  • VS Code Version: 1.73.1
  • OS Version: Windows_NT x64 10.0.19044

Steps to Reproduce:

  1. Create new markdown file
  2. Type a text:
text[^1]
[^1]: footnote
  1. See problems:
    (×) No link definition found: '^1' (link.no-such-reference) [Ln 1, Col 6]
    2022-11-22 14_23_58-test md - 555 - Visual Studio Code
@GeorgyKwe
Copy link

Try separating footnotes and citations by one line.

@mail2nnv
Copy link
Author

Try separating footnotes and citations by one line.

Nothing changed.
2022-11-24 11_34_58-test md - 555 - Visual Studio Code

@mjbvz mjbvz transferred this issue from microsoft/vscode Nov 28, 2022
@mjbvz mjbvz added the bug Issue identified by VS Code Team member as probable bug label Dec 5, 2022
@benblank
Copy link

benblank commented Feb 6, 2023

I'm sure this needs a more thorough look from someone familiar with the parser, but a quick check suggests that this behavior is the result of a conflict between how reference links are parsed and how link definitions are parsed.

Specifically, link definitions are explicitly not recognized if the reference name starts with a caret. (Note the (?!\^).)

const definitionPattern = /^([\t ]*\[(?!\^)((?:\\\]|[^\]])+)\]:\s*)([^<]\S*|<[^>]+>)/gm;

Conversely, reference links aren't subject to that exclusion. (Called out here as the "link def".)

const referenceLinkPattern = new RegExp(
r`(^|[^\]\\])` + // Must not start with another bracket (workaround for lack of support for negative look behinds)
r`(?:` +
/**/r`(?:` +
/****/r`(` + // Start link prefix
/******/r`!?` + // Optional image ref
/******/r`\[((?:` +// Link text
/********/r`\\\]|` + // escaped bracket, or...
/********/r`[^\[\]]|` + //non bracket char, or...
/********/r`\[[^\[\]]*\]` + // matched bracket pair
/******/`+)*)\]` + // end link text
/******/r`\[\s*?` + // Start of link def
/****/r`)` + // end link prefix
/****/r`(` +
/******/r`[^\]]*?)\]` + //link def
/******/r`|` +
/******/r`\[\s*?([^\\\]]*?)\s*\])(?![\(])` +
r`)`,
'gm');

As a result, footnotes appear to be interpreted as [shorthand]-style reference links which simply happen to start with a caret. But because the matching footnote definition isn't recognized as a link definition, the language service sees this as a link without a definition.

By my read, a fix for this could be as simple as removing (?!\^) from definitionPattern. Unless there's something else in the way, that should allow the parser to find the link definition. It'll still think the footnote is a link, though, and I don't know whether that could cause other issues.

@villeodell
Copy link

Just for additional context, even though most people's use case for this is footnotes, the following minimal example is parsed fine by commonmark.js (see here)

[^1]

[^1]: /url

However, vscode complains with

No link definition found: '^1'(link.no-such-reference)

@mjbvz mjbvz added this to the Backlog milestone Dec 6, 2023
@hellt
Copy link

hellt commented Sep 9, 2024

footnotes are often used in rich documentation sites powered by mkdocs and the likes. Would be great to see this fixed

a few examples with footnotes that are not captured as a link in the current vscode markdown lsp:

[`Makefile`][makefile][^1]

`make`[^4]

[`text`](url)[^5]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue identified by VS Code Team member as probable bug
Projects
None yet
Development

No branches or pull requests

6 participants