From 667205a1a99c5ca4b0b3793c7819d22c9bd25a36 Mon Sep 17 00:00:00 2001 From: Kelly Joseph Price Date: Mon, 28 Oct 2024 13:35:38 -0700 Subject: [PATCH 1/2] fix: migrating tables with html --- __tests__/migration/tables.test.ts | 30 ++++++++++++++++++++++++++++++ processor/migration/table-cell.ts | 7 +++++-- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/__tests__/migration/tables.test.ts b/__tests__/migration/tables.test.ts index 084ad487f..fd974484e 100644 --- a/__tests__/migration/tables.test.ts +++ b/__tests__/migration/tables.test.ts @@ -214,6 +214,36 @@ ${JSON.stringify( `); }); + it('compiles tables with html', () => { + const md = ` +| Teléfono | +| ------------------------------------------------------------------ | +|

¿Necesitas ayuda?

Llámanos al +52 33 11224455

| + `; + const mdx = rmdx.mdx(rmdx.mdastV6(md)); + + expect(mdx).toMatchInlineSnapshot(` + " + + + + + + + + + + + +
+ Teléfono +
+

¿Necesitas ayuda?

Llámanos al +52 33 11224455

+
+ " + `); + }); + it('does not muck with regular emphasis in tables', () => { const md = ` [block:parameters] diff --git a/processor/migration/table-cell.ts b/processor/migration/table-cell.ts index 162d6c07b..f9fec18d3 100644 --- a/processor/migration/table-cell.ts +++ b/processor/migration/table-cell.ts @@ -5,6 +5,7 @@ import * as rdmd from '@readme/markdown-legacy'; import { visit, SKIP } from 'unist-util-visit'; const magicIndex = (i: number, j: number) => `${i === 0 ? 'h' : `${i - 1}`}-${j}`; +const isInlineHtml = (node: $TSFixMe) => node.type === 'html' && !node.block; // @note: This regex is detect malformed lists that were created by the // markdown editor. Consider the following markdown: @@ -62,8 +63,10 @@ const migrateTableCells = (vfile: VFile) => (table: Table) => { children = rdmd.mdast(string).children; } - // eslint-disable-next-line no-param-reassign - cell.children = children.length > 1 ? children : [{ type: 'paragraph', children } as PhrasingContent]; + cell.children = + children.length > 1 && !children.some(isInlineHtml) + ? children + : ([{ type: 'paragraph', children }] as PhrasingContent[]); return SKIP; }); From 36bae342531c54baeff038901c34a3029fa70cb1 Mon Sep 17 00:00:00 2001 From: Kelly Joseph Price Date: Mon, 28 Oct 2024 17:09:44 -0700 Subject: [PATCH 2/2] lint: ts --- processor/migration/table-cell.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/processor/migration/table-cell.ts b/processor/migration/table-cell.ts index f9fec18d3..31fe381cd 100644 --- a/processor/migration/table-cell.ts +++ b/processor/migration/table-cell.ts @@ -5,7 +5,7 @@ import * as rdmd from '@readme/markdown-legacy'; import { visit, SKIP } from 'unist-util-visit'; const magicIndex = (i: number, j: number) => `${i === 0 ? 'h' : `${i - 1}`}-${j}`; -const isInlineHtml = (node: $TSFixMe) => node.type === 'html' && !node.block; +const isInlineHtml = node => node.type === 'html' && !node.block; // @note: This regex is detect malformed lists that were created by the // markdown editor. Consider the following markdown: