pulldown-cmark/pulldown-cmark

Support table rows with additional columns than header

Closed this issue · 2 comments

Given the following table

|   1  |   2  | 
|------|------|
| test | asdf | 1234 |

pulldown-cmark gives the following events (notice there is no event for the 1234 cell):

1..56 Start(Table([None, None]))
1..17 Start(TableHead)
5..6 Start(TableCell)
5..6 Text(Borrowed("1"))
5..6 End(TableCell)
12..13 Start(TableCell)
12..13 Text(Borrowed("2"))
12..13 End(TableCell)
1..17 End(TableHead)
33..56 Start(TableRow)
35..39 Start(TableCell)
35..39 Text(Borrowed("test"))
35..39 End(TableCell)
42..46 Start(TableCell)
42..46 Text(Borrowed("asdf"))
42..46 End(TableCell)
33..56 End(TableRow)
1..56 End(Table([None, None]))

Would it be possible to get an event for the final table cell in the last row even though the table is defined as only having two columns?

By the way, in case you didn't see, this library is now being used in Deno for markdown code formatting with deno fmt 🙂

We're mostly trying to follow GitHub's table markdown standard (GFM) here, and it seems that the third cell in your example is dropped here too:

1 2
test asdf

I am not sure that we can accommodate this use case while staying aligned with GFM without adding additional complexity like an additional option. Without actually looking at the code, I am fairly certain all the cells are actually parsed, so if there is a way to expose these cells in a way that is compatible with GFM, the implementation should be trivial.

Happy to hear that we can be useful to Deno in some way. Awesome project!

@marcusklaas thanks for explaining and that makes a lot of sense! I see it dropping the excess cells here: https://github.com/raphlinus/pulldown-cmark/blob/d99667b3a8843744494366799025dcea614ff866/src/firstpass.rs#L284

I think I will attempt to parse this out manually as I've been doing in some other areas.