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

LinkReferenceDefinition takes over sourceSpans from a block following it #315

Closed
obask opened this issue Mar 29, 2024 · 2 comments · Fixed by #318
Closed

LinkReferenceDefinition takes over sourceSpans from a block following it #315

obask opened this issue Mar 29, 2024 · 2 comments · Fixed by #318
Labels

Comments

@obask
Copy link

obask commented Mar 29, 2024

Steps to reproduce the problem (provide example Markdown if applicable):

Run this example with IncludeSourceSpans.BLOCKS https://spec.commonmark.org/0.31.2/#example-210

import org.commonmark.node.Node;
import org.commonmark.parser.IncludeSourceSpans;
import org.commonmark.parser.Parser;

public class Main {
    public static void main(String[] args) {
        Parser parser = Parser.builder().includeSourceSpans(IncludeSourceSpans.BLOCKS).build();
        String input = "[foo]: /url\n\"title\" ok";
        Node node = parser.parse(input);
        System.out.println("LinkReferenceDefinition spans: " + node.getFirstChild().getSourceSpans());
        System.out.println("Paragraph(last child)   spans: " + node.getLastChild().getSourceSpans());
    }
}

Expected behavior:

It should assign source spans to blocks

LinkReferenceDefinition spans: []
Paragraph(last child)   spans: [SourceSpan{line=1, column=0, length=10}]

Actual behavior:

It only assigns source spans to a LinkReferenceDefinition which is not a block

LinkReferenceDefinition spans: [SourceSpan{line=0, column=0, length=11}, SourceSpan{line=1, column=0, length=10}]
Paragraph(last child)   spans: []

PS [unrelated] a top level Document should probably only contain Blocks while LinkReferenceDefinition is a Node

@obask obask added the bug label Mar 29, 2024
robinst added a commit that referenced this issue Apr 6, 2024
An input like this:

```
[foo]: /url
"title" bad
```

Means the second line is just a paragraph because only spaces/tabs are allowed
after a title. The parser used to set the title to "title" in this case and
assign the source span of the second line to the definition, which is wrong.

Fixes #315.
@robinst
Copy link
Collaborator

robinst commented Apr 6, 2024

Thanks! Raised a PR to fix this.

PS [unrelated] a top level Document should probably only contain Blocks while LinkReferenceDefinition is a Node

Link reference definitions are a bit of an odd one in the way they're parsed. But in the spec, they're listed under blocks: https://spec.commonmark.org/0.31.2/#link-reference-definitions

We should probably change them to extends Block instead of extends Node. Thoughts? I made the change and none of the tests break, but it's technically an API change.

@robinst
Copy link
Collaborator

robinst commented Apr 26, 2024

We should probably change them to extends Block instead of extends Node. Thoughts? I made the change and none of the tests break, but it's technically an API change.

Done in 3038d47

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

Successfully merging a pull request may close this issue.

2 participants