tree-sitter-grammars / tree-sitter-markdown

Markdown grammar for tree-sitter
MIT License
425 stars 55 forks source link

bug: `link_destination` should not include `<>` #174

Open tbung opened 3 hours ago

tbung commented 3 hours ago

Did you check existing issues?

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

No response

Describe the bug

The destination in an inline link can be enclosed in angle braces, so the link can include whitespace. According to the spec, the angle braces do not belong to the link destination:

a sequence of zero or more characters between an opening < and a closing > that contains no line endings or unescaped < or > characters

It also makes semantic sense, that what ever is parsed as link_destination can be used as a file path or url. This is also the context this came up in, because neovim tries to open the url with the angle braces (see https://github.com/nvim-treesitter/nvim-treesitter/issues/7369).

I have a crude fix ready and will submit a pull request once I wrote a test, if you agree that this should be changed.

Steps To Reproduce/Bad Parse Tree

[example](<https://example.com>)

gets parsed as

(inline [0, 0] - [1, 0]
  (inline_link [0, 0] - [0, 32]
    (link_text [0, 1] - [0, 8])
    (link_destination [0, 10] - [0, 31])))

Expected Behavior/Parse Tree

(inline [0, 0] - [1, 0]
  (inline_link [0, 0] - [0, 32]
    (link_text [0, 1] - [0, 8])
    (link_destination [0, 11] - [0, 30])))

Repro

No response

tbung commented 2 hours ago

Actually I have no idea how to create additional tests for this, as far as I understand tests do not support ranges or anonymous nodes. Let me know if there is a way I am not seeing.