tree-sitter-grammars / tree-sitter-markdown

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

Changes needed for Neovim folding #91

Open ixru opened 1 year ago

ixru commented 1 year ago

Continuation of https://github.com/nvim-treesitter/nvim-treesitter/pull/3442

image

Image shows highlighted the relevant part, marked by the cursor.

What would solve the problem is if the block_continuation whitespace was moved from belonging to the paragraphs to belonging to the list items. The block_continuation at line 24, to belong to the list_item at line 25 (last part of highlight). 7 -> 9 (first part of highlight), and so with all the others. I don't know what purpose it serves, so I rely on you.

I also notice how the block continuation at line 7 is split, half to the continuation half to the marker, this is what makes me suspicious of the placement of block_continuation.

MDeiml commented 1 year ago

The block continuation problem is a bit non trivial because it's not always possible to put the corresponding nodes into the blocks they actually belong to. Think about a list item with a paragraph that's more than 1 line: the continuations in the middle would all need to belong to the paragraph and not the list items.

But it should be possible to make it more consistent for your use case. I guess you could specify it like this:

"All block continuations on a line should belong to the outermost node, that is open and does not close on this line, and that was open on the last line"

Or in other words, block continuations should never be the last part of a block, there should always be a line break in the same block somewhere later.

MDeiml commented 1 year ago

I'll see how it's possible to implement this, but shouldn't be all to hard.