thetarnav / streaming-markdown

Streaming markdown à la ChatGPT (WIP)
https://thetarnav.github.io/streaming-markdown/
MIT License
38 stars 3 forks source link

Ordered list numbering issue #7

Closed jdanyow closed 3 weeks ago

jdanyow commented 3 weeks ago

Thanks for this great lib- it's working really well in my project.

I sometimes see some issues with ordered lists where the start attribute is being set unexpectedly.

Couple tests that I think should pass but do not:

test_single_write("Ordered list",
    "1. hello\n"+
    "2. world\n"+
    "3. wave",
    [{
        type    : smd.Token.List_Ordered,
        children: [
            {
                type    : smd.Token.List_Item,
                children: ["hello"]
            },
            {
                type    : smd.Token.List_Item,
                children: ["world"]
            },
            {
                type    : smd.Token.List_Item,
                children: ["wave"]
            }
        ]
    }]
)

CleanShot 2024-11-06 at 21 06 47@2x

test_single_write("Ordered list",
    "1. hello\n\n"+
    "2. world\n\n"+
    "3. wave",
    [{
        type    : smd.Token.List_Ordered,
        children: [
            {
                type    : smd.Token.List_Item,
                children: ["hello"]
            },
            {
                type    : smd.Token.List_Item,
                children: ["world"]
            },
            {
                type    : smd.Token.List_Item,
                children: ["wave"]
            }
        ]
    }]
)

CleanShot 2024-11-06 at 21 07 18@2x

jdanyow commented 3 weeks ago

Example stream where the ordered list start attribute is being set unexpectedly:

CleanShot 2024-11-06 at 21 10 53@2x

jdanyow commented 3 weeks ago

commenting out this line resolves the issue where the <ol>'s start attribute is assigned unexpectedly: https://github.com/thetarnav/streaming-markdown/blob/588f5d4128750485da74d427ebdce4ccb25a4c62/smd.js#L538

But it does not fix the issue where list items with a line break between them are not rendered as a continuous list and are instead rendered as separate lists with one item each:

1. hello

2. world

3. wave
  1. hello

  2. world

  3. wave

thetarnav commented 3 weeks ago

Interesting, thank you for the detailed report. So these are two separate issues. Currently multiple newlines are used to exit out of tokens and start a new line, which has some unpolished edgecases around lists, blockquotes and such. In the this example, the start attr is being set after 5th list item, right?

thetarnav commented 3 weeks ago

Fixed the issue with start attr because it seemed like a simple overlooked mistake and nothing complicated. The one with newlines will probably be harder but I need to taclke it eventually.

jdanyow commented 3 weeks ago

Thank you! Wow that was quick. Sent you a coffee, much appreciated.