Skip to content

Incorrect unordered list structure, when indented by tabs #2172

Open

Description

@alexgarbarev

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
  • 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 + contentWhitespances

In 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!

Activity

  1. srawlins commented on Sep 29, 2025

    @srawlins
    Member

    Looks perfectly legit. Thanks for the issue, @alexgarbarev

    Looking at Babelmark, most implementations work as you describe above that you would expect. I think using tabRemaining is a good solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions