Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions __tests__/compilers/tables.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { visit, EXIT } from 'unist-util-visit';

import { mdast, mdx } from '../../index';

import { jsxTableWithInlineCodeWithPipe, tableWithInlineCodeWithPipe, tableWithPipe } from './tables/fixtures';

describe('table compiler', () => {
it('writes to markdown syntax', () => {
const markdown = `
Expand Down Expand Up @@ -338,4 +340,56 @@ describe('table compiler', () => {
mdx(ast);
}).not.toThrow();
});

describe('escaping pipes', () => {
it('compiles tables with pipes in inline code', () => {
expect(mdx(tableWithInlineCodeWithPipe)).toMatchInlineSnapshot(`
"| | |
| :----------- | :- |
| \`foo \\| bar\` | |
"
`);
});

it('compiles tables with pipes', () => {
expect(mdx(tableWithPipe)).toMatchInlineSnapshot(`
"| | |
| :--------- | :- |
| foo \\| bar | |
"
`);
});

it('compiles jsx tables with pipes in inline code', () => {
expect(mdx(jsxTableWithInlineCodeWithPipe)).toMatchInlineSnapshot(`
"<Table align={["left","left"]}>
<thead>
<tr>
<th style={{ textAlign: "left" }}>
force
jsx
</th>

<th style={{ textAlign: "left" }}>

</th>
</tr>
</thead>

<tbody>
<tr>
<td style={{ textAlign: "left" }}>
\`foo | bar\`
</td>

<td style={{ textAlign: "left" }}>

</td>
</tr>
</tbody>
</Table>
"
`);
});
});
});
233 changes: 233 additions & 0 deletions __tests__/compilers/tables/fixtures.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
export const tableWithInlineCodeWithPipe = {
type: 'root',
children: [
{
type: 'table',
children: [
{
type: 'tableRow',
children: [
{
type: 'tableHead',
children: [
{
type: 'paragraph',
children: [
{
type: 'plain',
value: '',
},
],
},
],
},
{
type: 'tableHead',
children: [
{
type: 'paragraph',
children: [
{
type: 'plain',
value: '',
},
],
},
],
},
],
},
{
type: 'tableRow',
children: [
{
type: 'tableCell',
children: [
{
type: 'paragraph',
children: [
{
type: 'plain',
value: '`foo | bar`',
},
],
},
],
},
{
type: 'tableCell',
children: [
{
type: 'paragraph',
children: [
{
type: 'plain',
value: '',
},
],
},
],
},
],
},
],
align: ['left', 'left'],
},
],
};

export const tableWithPipe = {
type: 'root',
children: [
{
type: 'table',
children: [
{
type: 'tableRow',
children: [
{
type: 'tableHead',
children: [
{
type: 'paragraph',
children: [
{
type: 'plain',
value: '',
},
],
},
],
},
{
type: 'tableHead',
children: [
{
type: 'paragraph',
children: [
{
type: 'plain',
value: '',
},
],
},
],
},
],
},
{
type: 'tableRow',
children: [
{
type: 'tableCell',
children: [
{
type: 'paragraph',
children: [
{
type: 'plain',
value: 'foo | bar',
},
],
},
],
},
{
type: 'tableCell',
children: [
{
type: 'paragraph',
children: [
{
type: 'plain',
value: '',
},
],
},
],
},
],
},
],
align: ['left', 'left'],
},
],
};

export const jsxTableWithInlineCodeWithPipe = {
type: 'root',
children: [
{
type: 'table',
children: [
{
type: 'tableRow',
children: [
{
type: 'tableHead',
children: [
{
type: 'paragraph',
children: [
{
type: 'plain',
value: 'force\njsx',
},
],
},
],
},
{
type: 'tableHead',
children: [
{
type: 'paragraph',
children: [
{
type: 'plain',
value: '',
},
],
},
],
},
],
},
{
type: 'tableRow',
children: [
{
type: 'tableCell',
children: [
{
type: 'paragraph',
children: [
{
type: 'plain',
value: '`foo | bar`',
},
],
},
],
},
{
type: 'tableCell',
children: [
{
type: 'paragraph',
children: [
{
type: 'plain',
value: '',
},
],
},
],
},
],
},
],
align: ['left', 'left'],
},
],
};
Loading
Loading