Skip to content

LinkReferenceDefinition takes over sourceSpans from a block following it #315

@obask

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

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