Skip to content

LinkReferenceDefinition takes over sourceSpans from a block following it #315

Closed

Description

@obask

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

Activity

  1. added a commit that references this issue on Apr 6, 2024
    b570e1b
  2. robinst commented on Apr 6, 2024

    @robinst
    Collaborator

    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.

  3. robinst commented on Apr 26, 2024

    @robinst
    Collaborator

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions