Skip to content

Commit

Permalink
fix: dont treat escapes as flow (#1040)
Browse files Browse the repository at this point in the history
[![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
  • Loading branch information
kellyjosephprice authored Dec 11, 2024
1 parent a3b7f50 commit 4692ece
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
17 changes: 17 additions & 0 deletions __tests__/migration/tables.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -486,4 +486,21 @@ ${JSON.stringify(
"
`);
});

it('compiles tables with leading escapes', () => {
const md = `
| Col 1 | Col 2 |
| --------- | ----- |
| \\_foo_\\ | bar |
`;

const mdx = migrate(md);

expect(mdx).toMatchInlineSnapshot(`
"| Col 1 | Col 2 |
| --------- | ----- |
| \\_foo\\_\\ | bar |
"
`);
});
});
10 changes: 2 additions & 8 deletions processor/migration/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@ import imagesTransformer from './images';
import linkReferenceTransformer from './linkReference';
import tableCellTransformer from './table-cell';

const transformers = [
emphasisTransformer,
imagesTransformer,
linkReferenceTransformer,
tableCellTransformer,
];

export default transformers
const transformers = [emphasisTransformer, imagesTransformer, linkReferenceTransformer, tableCellTransformer];

export default transformers;
2 changes: 1 addition & 1 deletion processor/transform/tables-to-jsx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const visitor = (table: Table, index: number, parent: Parents) => {
parent.children.splice(index, 1, { type: 'text', value: '\n' });
});

if (!phrasing(content)) {
if (!phrasing(content) && content.type !== 'escape') {
hasFlowContent = true;
return EXIT;
}
Expand Down

0 comments on commit 4692ece

Please sign in to comment.