stsewd / tree-sitter-rst

reStructuredText grammar for tree-sitter
https://stsewd.dev/tree-sitter-rst/
MIT License
50 stars 7 forks source link

Fix block quote marker seen as adornment #34

Closed Carreau closed 9 months ago

Carreau commented 2 years ago

This fixes an edge case where a blockquote marker on a line just after a paragraph is seen as an adornment and thus lead to a section being seen.

I found a couple of case in a few library with this.

I think a better fix would be to look back at the title length (is it possible ? ), or maybe even to require titles to be at least 3 in length ?

Carreau commented 2 years ago

I'm also not a C person, so I'm not sure what I am doing.

stsewd commented 2 years ago

Hi, thanks for the PR! I think you are trying to fix https://github.com/stsewd/tree-sitter-rst/issues/27?

I think we may need to check other things other than just the length of the adornment, some examples (parsed using docutils):

On
::
   Block
On
::

   Block

Those are interpreted as a title followed by blockquote (as currently parsed), this is also true if the length of the adornment is greater than 2 or if the length of the title is 1.

But, things get interesting when the title is greater than 2

One
::
   Block
One
::

   Block

which is the same as writing

One ::

   Block

This is also invalid (test.rst:4: (WARNING/2) Literal block expected; none found)

One
::

Block

So, looks like we need to check if the length of the title is greater than 2 and the length of the adornment is two (::).

Carreau commented 2 years ago

Hi, thanks for the PR! I think you are trying to fix #27?

Yes, that is correct. And yes I couldn't really figure out how to compare the title length to the adornment length.

I believe the adornment are supposed to be as long as, if not longer than the title, and ai think docutils have some leeway on that, and of course if your title is 2 chars or less things can become ambiguous.