micromark / micromark-extension-gfm-table

micromark extension to support GFM tables
https://unifiedjs.com
MIT License
6 stars 6 forks source link

problem about parsing empty cell without any whitespaces #3

Closed wataru-chocola closed 2 years ago

wataru-chocola commented 2 years ago

Initial checklist

Affected packages and versions

1.0.2

Link to runnable example

No response

Steps to reproduce

micromark-extension-gfm-table doesn't seem to generate any events corresponding to empy cell which has no whitespace, like:

|a|b|c|
|-|-|-|
|1|2|3|
|1||3|

In remark layer, here is PoC:

import { unified } from "unified";
import remarkParse from "remark-parse";
import remarkGfm from "remark-gfm";
import remarkRehype from "remark-rehype";
import remarkStringify from "rehype-stringify";

const processor = unified()
  .use(remarkParse)
  .use(remarkGfm)
  .use(remarkRehype)
  .use(remarkStringify);

const md = `
|a|b|c|
|-|-|-|
|1|2|3|
|1||3|
`;

processor.process(md).then((result) => {
  console.log(result.value);
});

I checked mdast tree and generated events, and found there's no event which corresponds to empty cell.

[ 'enter', 'tableRow', '|1||3|' ]
[ 'enter', 'tableData', '|1|' ]
[ 'enter', 'tableCellDivider', '|' ]
[ 'exit', 'tableCellDivider', '|' ]
[ 'enter', 'tableContent', '1' ]
[ 'enter', 'chunkText', '1' ]
[ 'exit', 'chunkText', '1' ]
[ 'exit', 'tableContent', '1' ]
[ 'enter', 'tableCellDivider', '|' ]
[ 'exit', 'tableCellDivider', '|' ]
[ 'exit', 'tableData', '|1|' ]
[ 'enter', 'tableData', '|3|' ]
[ 'enter', 'tableCellDivider', '|' ]
[ 'exit', 'tableCellDivider', '|' ]
[ 'enter', 'tableContent', '3' ]
[ 'enter', 'chunkText', '3' ]
[ 'exit', 'chunkText', '3' ]
[ 'exit', 'tableContent', '3' ]
[ 'enter', 'tableCellDivider', '|' ]
[ 'exit', 'tableCellDivider', '|' ]
[ 'exit', 'tableData', '|3|' ]
[ 'exit', 'tableRow', '|1||3|' ]

Expected behavior

GitHub produces the following HTML. I expect micromark-extension-gfm-table (or mdast-gfm-table or remark-gfm) would do.

<table>
<thead>
<tr>
<th>a</th>
<th>b</th>
<th>c</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
<tr>
<td>1</td>
<td></td>
<td>3</td>
</tr>
</tbody>
</table>

Actual behavior

The following html is generated.

<table>
<thead>
<tr>
<th>a</th>
<th>b</th>
<th>c</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
<tr>
<td>1</td>
<td>3</td>
<td></td>
</tr>
</tbody>
</table>

Runtime

Node v16

Package manager

npm v7

OS

Linux

Build and bundle tools

No response

wooorm commented 2 years ago

looks like a bug!

github-actions[bot] commented 2 years ago

Hi! This was marked as ready to be worked on! Note that while this is ready to be worked on, nothing is said about priority: it may take a while for this to be solved.

Is this something you can and want to work on?

Team: please use the area/* (to describe the scope of the change), platform/* (if this is related to a specific one), and semver/* and type/* labels to annotate this. If this is first-timers friendly, add good first issue and if this could use help, add help wanted.

wooorm commented 2 years ago

released!

wataru-chocola commented 2 years ago

Thank you!