Skip to content

Commit

Permalink
fix: lists in table headers (#943)
Browse files Browse the repository at this point in the history
| [![PR App][icn]][demo] | RM-9793 |
| :--------------------: | :--------: |

## 🧰 Changes

Fixes saving lists (other blocks too) in table headers.

## 🧬 QA & Testing

Kind of hard to test outside the editor. But I've been testing by
running `make mdx` and playing around in the styleguidist playground
thingy.

- [Broken on production][prod].
- [Working in this PR app][demo].

[demo]: https://markdown-pr-PR_NUMBER.herokuapp.com
[prod]: https://SUBDOMAIN.readme.io
[icn]:
https://user-images.githubusercontent.com/886627/160426047-1bee9488-305a-4145-bb2b-09d8b757d38a.svg
  • Loading branch information
kellyjosephprice authored Jul 19, 2024
1 parent 1b86106 commit 6a2e80f
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
60 changes: 60 additions & 0 deletions __tests__/compilers/tables.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,4 +264,64 @@ describe('table compiler', () => {
`.trim(),
);
});

it('compiles to jsx if there is a single list item', () => {
const doc = `
<Table>
<thead>
<tr>
<th>
* list
</th>
<th>
th 2
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
cell 1
</td>
<td>
cell 2
</td>
</tr>
</tbody>
</Table>
`;

const tree = mdast(doc);

expect(mdx(tree).trim()).toMatchInlineSnapshot(`
"<Table>
<thead>
<tr>
<th>
* list
</th>
<th>
th 2
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
cell 1
</td>
<td>
cell 2
</td>
</tr>
</tbody>
</Table>"
`);
});
});
4 changes: 3 additions & 1 deletion processor/transform/tables-to-jsx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const alignToStyle = (align: 'left' | 'center' | 'right' | null) => {
};
};

const isTableCell = (node: Node) => ['tableHead', 'tableCell'].includes(node.type);

const visitor = (table: Table, index: number, parent: Parents) => {
let hasFlowContent = false;

Expand All @@ -39,7 +41,7 @@ const visitor = (table: Table, index: number, parent: Parents) => {
});
};

visit(table, 'tableCell', tableCellVisitor);
visit(table, isTableCell, tableCellVisitor);
if (!hasFlowContent) {
table.type = 'table';
return;
Expand Down

0 comments on commit 6a2e80f

Please sign in to comment.