Skip to content

Commit 4692ece

Browse files
fix: dont treat escapes as flow (#1040)
[![PR App][icn]][demo] | Ref CX-1610 :-------------------:|:----------: ## 🧰 Changes Fixes migrating tables with leading escapes. The `phrasing` util is not aware of the `escape` node type, as it is from a previous version of `mdast`. This was confusing our `tables-to-jsx` transformer. It would look at tables and decide if it could be compiled to markdown format, eg: ``` | a | b | |---|---| | 1 | 2 | ``` or if it should be compiled to JSX format, eg: ```jsx <Table> <TableHead> <TableRow> <TableCell>a</TableCell> <TableCell>b</TableCell> </TableRow> </TableHead> <TableBody> <TableRow> <TableCell>1</TableCell> <TableCell>2</TableCell> </TableRow> </TableBody> </Table> ``` ## 🧬 QA & Testing - [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
1 parent a3b7f50 commit 4692ece

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

__tests__/migration/tables.test.ts

+17
Original file line numberDiff line numberDiff line change
@@ -486,4 +486,21 @@ ${JSON.stringify(
486486
"
487487
`);
488488
});
489+
490+
it('compiles tables with leading escapes', () => {
491+
const md = `
492+
| Col 1 | Col 2 |
493+
| --------- | ----- |
494+
| \\_foo_\\ | bar |
495+
`;
496+
497+
const mdx = migrate(md);
498+
499+
expect(mdx).toMatchInlineSnapshot(`
500+
"| Col 1 | Col 2 |
501+
| --------- | ----- |
502+
| \\_foo\\_\\ | bar |
503+
"
504+
`);
505+
});
489506
});

processor/migration/index.ts

+2-8
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,6 @@ import imagesTransformer from './images';
33
import linkReferenceTransformer from './linkReference';
44
import tableCellTransformer from './table-cell';
55

6-
const transformers = [
7-
emphasisTransformer,
8-
imagesTransformer,
9-
linkReferenceTransformer,
10-
tableCellTransformer,
11-
];
12-
13-
export default transformers
6+
const transformers = [emphasisTransformer, imagesTransformer, linkReferenceTransformer, tableCellTransformer];
147

8+
export default transformers;

processor/transform/tables-to-jsx.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const visitor = (table: Table, index: number, parent: Parents) => {
3636
parent.children.splice(index, 1, { type: 'text', value: '\n' });
3737
});
3838

39-
if (!phrasing(content)) {
39+
if (!phrasing(content) && content.type !== 'escape') {
4040
hasFlowContent = true;
4141
return EXIT;
4242
}

0 commit comments

Comments
 (0)