Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
68 changes: 68 additions & 0 deletions __tests__/compilers/tables.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ import { visit, EXIT } from 'unist-util-visit';

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

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

describe('table compiler', () => {
it('writes to markdown syntax', () => {
const markdown = `
Expand Down Expand Up @@ -338,4 +345,65 @@ 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 escaped pipes in inline code', () => {
expect(mdx(tableWithInlineCodeWithEscapedPipe)).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>
"
`);
});
});
});
311 changes: 311 additions & 0 deletions __tests__/compilers/tables/fixtures.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,311 @@
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 tableWithInlineCodeWithEscapedPipe = {
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