tree-sitter-grammars / tree-sitter-markdown

Markdown grammar for tree-sitter
MIT License
379 stars 45 forks source link

Bug: code bolck in quote block #26

Closed black-desk closed 2 years ago

black-desk commented 2 years ago

something like this will break the AST:

> ```bash
> git add --all
> git commit -m "msg"
> ```

playground shows that:

block_quote [0, 0] - [4, 0]
  block_quote_marker [0, 0] - [0, 2]
  fenced_code_block [0, 2] - [4, 0]
    info_string [0, 5] - [0, 9]
      language [0, 5] - [0, 9]
    block_quote_marker [1, 0] - [1, 2]
    code_fence_content [1, 2] - [3, 2]
      ERROR [1, 2] - [3, 1]
        command [1, 2] - [1, 15]
          name: command_name [1, 2] - [1, 5]
            word [1, 2] - [1, 5]
          argument: word [1, 6] - [1, 9]
          argument: word [1, 10] - [1, 15]
        command [2, 0] - [2, 21]
          file_redirect [2, 0] - [2, 5]
            destination: word [2, 2] - [2, 5]
          name: command_name [2, 6] - [2, 12]
            word [2, 6] - [2, 12]
          argument: word [2, 13] - [2, 15]
          argument: string [2, 16] - [2, 21]
      block_quote_marker [2, 0] - [2, 2]
      block_quote_marker [3, 0] - [3, 2]

It seems this problem is very hard to fix.

MDeiml commented 2 years ago

I didn't think of this case. The >s are marked as being part of the code block and get forwarded to the bash grammar.

black-desk commented 2 years ago

It seems that there will be no way to fix this if it is not possible to pass something that is not continuous as a whole thing to another tree-sitter parser.

MDeiml commented 2 years ago

There is actually. See @combined as explained in the "Injections" section here. But I think that would mean parsing all code blocks as if they were one document? I'm not sure how that actually works in this particular use case.

MDeiml commented 2 years ago

This was fixed by the most recent update. If you are using nvim-treesitter update the plugin and then run :TSUpdate to get the newest parser. You might need some changes to your config, see https://github.com/MDeiml/tree-sitter-markdown/issues/45#issuecomment-1167311394

black-desk commented 2 years ago

Thanks