lepture/mistune

table parsing issues related to leading/missing pipe

Mark-L6n opened this issue · 2 comments

We are parsing a large number of markdown tables and having issues with whether a leading pipe exists or not in table rows/headers. In the below example, all 6 markdown tables result in correct tables in github preview, VS Code, and MacDown. However, in Mistune, only #1 and #2 come out correctly.

  1. It appears that Mistune wants all lines of a table formatted with (or without) a leading pipe in the same way, as in 1 & 2. However, with a mixture, as in 3, 4 & 5, the results aren't correct. It appears that somehow, each line/row isn't parsed on its own to be valid.
  2. in 6, if the first row in a cell is empty, a leading pipe is required. However, this results in an extra cell in a table of 6's structure.
## table 1
|col1|col2|
|---|---|
|r1c1|r1c2|
|r2c2|r2c2|

## table 2

col1|col2
---|---
r1c1|r1c2
r2c2|r2c2

## table 3

|col1|col2|
|---|---|
r1c1|r1c2
r2c2|r2c2

## table 4

col1|col2
|---|---|
r1c1|r1c2
r2c2|r2c2

## table 5

col1|col2
|---|---|
r1c1|r1c2
r2c2|r2c2

## table 6 (like 2 with leading blank cell)

col1|col2
---|---
r1c1|r1c2
||r2c2

Github output:

table 1

col1 col2
r1c1 r1c2
r2c2 r2c2

table 2

col1 col2
r1c1 r1c2
r2c2 r2c2

table 3

col1 col2
r1c1 r1c2
r2c2 r2c2

table 4

col1 col2
r1c1 r1c2
r2c2 r2c2

table 5

col1 col2
r1c1 r1c2
r2c2 r2c2

table 6 (like 2 with leading blank cell)

col1 col2
r1c1 r1c2
r2c2

This is how HTML returned by Mistune 2.02 appears:

table 1

col1 col2
r1c1 r1c2
r2c2 r2c2

table 2

col1 col2
r1c1 r1c2
r2c2 r2c2

table 3

col1 col2

r1c1|r1c2
r2c2|r2c2

table 4

col1|col2
|---|---|
r1c1|r1c2
r2c2|r2c2

table 5

col1|col2
|---|---|
r1c1|r1c2
r2c2|r2c2

table 6 (like 2 with leading blank cell)

col1 col2
r1c1 r1c2
r2c2

We are following table spec from Markdown Extra