Skip to content

Inconsistent parsing of link text nodes #376

@JamieMagee

Description

@JamieMagee

I'm seeing an issue where the child text nodes of some link text is being split. For example:

doc = Commonmarker.parse("[@ewd](https://example.com)")
doc.inspect
# "#<Commonmarker::Node(document): source_position={start_line: 1, start_column: 1, end_line: 1, end_column: 27} children=[#<Commonmarker::Node(paragraph): source_position={start_line: 1, start_column: 1, end_line: 1, end_column: 27} children=[#<Commonmarker::Node(link): source_position={start_line: 1, start_column: 1, end_line: 1, end_column: 27}, url=\"https://example.com\", title=\"\" children=[#<Commonmarker::Node(text): source_position={start_line: 1, start_column: 2, end_line: 1, end_column: 3}, string_content=\"@e\">, #<Commonmarker::Node(text): source_position={start_line: 1, start_column: 4, end_line: 1, end_column: 4}, string_content=\"w\">, #<Commonmarker::Node(text): source_position={start_line: 1, start_column: 5, end_line: 1, end_column: 5}, string_content=\"d\">]>]>]>\n"

The link contains 3 children nodes with the text @e, w, and d respectively. However, if I change the content

doc = Commonmarker.parse("[@eaa](https://example.com)")
doc.inspect
# "#<Commonmarker::Node(document): source_position={start_line: 1, start_column: 1, end_line: 1, end_column: 27} children=[#<Commonmarker::Node(paragraph): source_position={start_line: 1, start_column: 1, end_line: 1, end_column: 27} children=[#<Commonmarker::Node(link): source_position={start_line: 1, start_column: 1, end_line: 1, end_column: 27}, url=\"https://example.com\", title=\"\" children=[#<Commonmarker::Node(text): source_position={start_line: 1, start_column: 2, end_line: 1, end_column: 5}, string_content=\"@eaa\">]>]>]>\n"

I get a single child node with the text @eaa.

If I set autolink to false for the first example, I get the expected behaviour:

doc = Commonmarker.parse("[@ewd](https://example.com)", options: { extension: { autolink: false } })
doc.inspect
# "#<Commonmarker::Node(document): source_position={start_line: 1, start_column: 1, end_line: 1, end_column: 27} children=[#<Commonmarker::Node(paragraph): source_position={start_line: 1, start_column: 1, end_line: 1, end_column: 27} children=[#<Commonmarker::Node(link): source_position={start_line: 1, start_column: 1, end_line: 1, end_column: 27}, url=\"https://example.com\", title=\"\" children=[#<Commonmarker::Node(text): source_position={start_line: 1, start_column: 2, end_line: 1, end_column: 5}, string_content=\"@ewd\">]>]>]>\n"

A single child text node with the content @ewd.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions