Skip to content

bug: image markdown incorrectly parsed when more than 8 images are on adjacent lines #186

@marchyman

Description

@marchyman

Did you check existing issues?

  • I have read all the tree-sitter docs if it relates to using the parser
  • I have searched the existing issues

Tree-Sitter CLI Version, if relevant (output of tree-sitter --version)

No response

Describe the bug

Tree-sitter parses an image link ![alt text](url-or-file-path) as an inline_link when the image link is followed by 8 more images. 8 images in a row will parse correctly. The first image will be parsed incorrect if a 9th image is added. If a 10th image is added the 2nd image will be parsed incorrectly, etc. Breaking the set of images up into groups of 8 or less by adding empty lines results in a correct tree.

I am not a tree-sitter user save that I am an nvim user. I discovered this using the nvim InspectTree command when trying to figure out a side effect of this bug.

Steps To Reproduce/Bad Parse Tree

Create a markdown file containing 9 or more image links
Parse the file
Inspect the resulting tree.

Expected Behavior/Parse Tree

This is the result when parsing a file containing 9 image lines.

(document ; [0, 0] - [9, 0]
  (section ; [0, 0] - [9, 0]
    (paragraph ; [0, 0] - [9, 0]
      (inline ; [0, 0] - [8, 16]
        (inline ; [0, 0] - [8, 16]
          (inline_link ; [0, 1] - [0, 16]    <=== this is incorrect, it should be (image ; ...
            (link_text) ; [0, 2] - [0, 5]
            (link_destination)) ; [0, 7] - [0, 15]
          (image ; [1, 0] - [1, 16]
            (image_description) ; [1, 2] - [1, 5]
            (link_destination)) ; [1, 7] - [1, 15]
          (image ; [2, 0] - [2, 16]
            (image_description) ; [2, 2] - [2, 5]
            (link_destination)) ; [2, 7] - [2, 15]
          (image ; [3, 0] - [3, 16]
            (image_description) ; [3, 2] - [3, 5]
            (link_destination)) ; [3, 7] - [3, 15]
          (image ; [4, 0] - [4, 16]
            (image_description) ; [4, 2] - [4, 5]
            (link_destination)) ; [4, 7] - [4, 15]
          (image ; [5, 0] - [5, 16]
            (image_description) ; [5, 2] - [5, 5]
            (link_destination)) ; [5, 7] - [5, 15]
          (image ; [6, 0] - [6, 16]
            (image_description) ; [6, 2] - [6, 5]
            (link_destination)) ; [6, 7] - [6, 15]
          (image ; [7, 0] - [7, 16]
            (image_description) ; [7, 2] - [7, 5]
            (link_destination)) ; [7, 7] - [7, 15]
          (image ; [8, 0] - [8, 16]
            (image_description) ; [8, 2] - [8, 5]
            (link_destination))))))) ; [8, 7] - [8, 15]

The input file contained these lines:

![img](img1.jpg)
![img](img2.jpg)
![img](img3.jpg)
![img](img4.jpg)
![img](img5.jpg)
![img](img6.jpg)
![img](img7.jpg)
![img](img8.jpg)
![img](img9.jpg)

Repro

See above.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions