arve0 / markdown-it-attrs

Add classes, identifiers and attributes to your markdown with {} curly brackets, similar to pandoc's header attributes
MIT License
300 stars 58 forks source link

Tables break in markdown-it v12 #113

Closed valtlai closed 3 years ago

valtlai commented 4 years ago

Markdown-it v12 was just released. We can’t just bump the markdown-it version because tables don’t work correctly without code changes. I’m not sure if markdown-it-attrs or markdown-it itself should be updated to fix the issue.

Markdown-it versions: 12.0.0

├── UNMET PEER DEPENDENCY markdown-it@12.0.0
└── markdown-it-attrs@3.0.3

Example input:

| Foo   | Baz   |
| ----- | ----- |
| sin   | cos   |
{.lorem}

Current output:

<table>
<thead>
<tr>
<th>Foo</th>
<th>Baz</th>
</tr>
</thead>
<tbody>
<tr>
<td>sin</td>
<td>cos</td>
</tr>
<tr>
<td class="lorem"></td>
<td></td>
</tr>
</tbody>
</table>

Expected output:

<table class="lorem">
<thead>
<tr>
<th>Foo</th>
<th>Baz</th>
</tr>
</thead>
<tbody>
<tr>
<td>sin</td>
<td>cos</td>
</tr>
</tbody>
</table>
schl3ck commented 4 years ago

I got it to apply the class to the <table> element by moving it to a seperate paragraph:

| Foo   | Baz   |
| ----- | ----- |
| sin   | cos   |

{.lorem}

Looks like markdown-it treats the last line as part of the table even when it doesn't contain any pipes.

valtlai commented 4 years ago

@schl3ck You’re right. That new behavior in markdown-it v12 is correct according to GitHub Flavored Markdown Spec.

Opened PR #114 to update markdown-it to v12 and a test to use a blank line after the table.