Skip to content

Commit e3f3e35

Browse files
fix: migrating magic block tables with breaks
1 parent 26b9b8d commit e3f3e35

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

__tests__/compilers/compatability.test.tsx

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,4 +330,66 @@ This is an image: <img src="http://example.com/#\\>" >
330330
"
331331
`);
332332
});
333+
334+
it.only('compiles parameter magic blocks with breaks to jsx', () => {
335+
const md = `
336+
[block:parameters]
337+
${JSON.stringify(
338+
{
339+
data: {
340+
'h-0': 'Term',
341+
'h-1': 'Definition',
342+
'0-0': 'Events',
343+
'0-1': 'Pseudo-list: \n● One \n● Two',
344+
},
345+
cols: 2,
346+
rows: 1,
347+
align: ['left', 'left'],
348+
},
349+
null,
350+
2,
351+
)}
352+
[/block]
353+
`;
354+
355+
const rmdx = mdx(rdmd.mdast(md));
356+
expect(rmdx).toMatchInlineSnapshot(`
357+
"<Table align={["left","left"]}>
358+
<thead>
359+
<tr>
360+
<th style={{ textAlign: "left" }}>
361+
Term
362+
</th>
363+
364+
<th style={{ textAlign: "left" }}>
365+
Definition
366+
</th>
367+
</tr>
368+
</thead>
369+
370+
<tbody>
371+
<tr>
372+
<td style={{ textAlign: "left" }}>
373+
Events
374+
</td>
375+
376+
<td style={{ textAlign: "left" }}>
377+
Pseudo-list:
378+
379+
380+
381+
382+
● One
383+
384+
385+
386+
387+
● Two
388+
</td>
389+
</tr>
390+
</tbody>
391+
</Table>
392+
"
393+
`);
394+
});
333395
});

processor/transform/tables-to-jsx.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ const visitor = (table: Table, index: number, parent: Parents) => {
2828
? (cell.children[0] as unknown as Paragraph).children[0]
2929
: cell.children[0];
3030

31+
// @note: Compatibility with RDMD. Ideally, I'd put this in a separate
32+
// transformer, but then there'd be some duplication.
33+
visit(cell, 'break', (_, index, parent) => {
34+
parent.children.splice(index, 1, { type: 'text', value: '\n' });
35+
});
36+
3137
if (!phrasing(content)) {
3238
hasFlowContent = true;
3339
return EXIT;

0 commit comments

Comments
 (0)