-
Notifications
You must be signed in to change notification settings - Fork 78
Description
Currently, if we try to parse list like that
* one
\t* nested one
\t* nested two
* two
it would be parsed into following structure
- one
- nested one
- nested two
- nested one
- two
while it's expected to be
- one
- nested one
- nested two
- two
After lots of debugging I found that in the list_syntax.dart file, in the parse method, there are two variables indent and currentIndent that are crucial to detect nested list.
And the currentIndent is calculated as:
final currentIndent = parser.current.content.indentation() +
(parser.current.tabRemaining ?? 0);while indent in this case is calculated as
indent = precedingWhitespaces + contentWhitespancesIn the case above, when we have list indented by tabs, we have tabRemaining as 2 for both nested lines of second level, but because indent is not taking into account tabRemaining there, it mistakenly adds unwanted nesting later, when we compare indent <= currentIndent (which is 2 <= 2 for the "nested two" element).
So my suggested fix is to change indent calculation by adding tabRemaining there:
indent = precedingWhitespaces +
contentWhitespances +
(parser.current.tabRemaining ?? 0)That way all tests are passing. But I'm not sure if we should also add the same fix to contentWhitespances >= 4 branch above, and I couldn't find a test case for that branch.
Could someone please validate the fix? Thanks!