Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: migrate export #1009

Merged
merged 3 commits into from
Nov 1, 2024
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
48 changes: 22 additions & 26 deletions __tests__/compilers/compatability.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import fs from 'node:fs';
import { vi } from 'vitest';
import { render, screen } from '@testing-library/react';

import { mdastV6, mdx, compile, run } from '../../index';
import { mdx, migrate, compile, run } from '../../index';

describe('compatability with RDMD', () => {
it('compiles glossary nodes', () => {
Expand Down Expand Up @@ -125,7 +125,7 @@ describe('compatability with RDMD', () => {
This is some in progress <!-- commented out stuff -->
`;

expect(mdx(mdastV6(md)).trim()).toBe('This is some in progress {/* commented out stuff */}');
expect(migrate(md).trim()).toBe('This is some in progress {/* commented out stuff */}');
});

it('compiles multi-line html comments to JSX comments', () => {
Expand All @@ -139,7 +139,7 @@ This is some in progress <!-- commented out stuff -->
-->
`;

expect(mdx(mdastV6(md)).trim()).toMatchInlineSnapshot(`
expect(migrate(md).trim()).toMatchInlineSnapshot(`
"## Wip

{/*
Expand All @@ -155,52 +155,52 @@ This is some in progress <!-- commented out stuff -->
This is a break: <br>
`;

expect(mdx(mdastV6(md)).trim()).toBe('This is a break: <br />');
expect(migrate(md).trim()).toBe('This is a break: <br />');
});

it.skip('closes un-closed self closing tags with a space', () => {
const md = `
This is a break: <br >
`;

expect(mdx(mdastV6(md)).trim()).toBe('This is a break: <br />');
expect(migrate(md).trim()).toBe('This is a break: <br />');
});

it.skip('closes complex un-closed self closing tags', () => {
const md = `
This is an image: <img src="http://example.com/#\\>" >
`;

expect(mdx(mdastV6(md)).trim()).toBe('This is an image: <img src="http://example.com/#\\>" />');
expect(migrate(md).trim()).toBe('This is an image: <img src="http://example.com/#\\>" />');
});

it('compiles escapes', () => {
const md = `
\\- not a list item
`;

expect(mdx(mdastV6(md)).trim()).toBe('\\- not a list item');
expect(migrate(md).trim()).toBe('\\- not a list item');
});

it('compiles escapes of backslashes', () => {
const md = `
\\\\**still emphatic**
`;

expect(mdx(mdastV6(md)).trim()).toBe('\\\\**still emphatic**');
expect(migrate(md).trim()).toBe('\\\\**still emphatic**');
});

it('compiles magic block images into blocks', () => {
const imageMd = fs.readFileSync('__tests__/fixtures/image-block-no-attrs.md', { encoding: 'utf8' });
const imageMdx = fs.readFileSync('__tests__/fixtures/image-block-no-attrs.mdx', { encoding: 'utf8' });

expect(mdx(mdastV6(imageMd))).toBe(imageMdx);
expect(migrate(imageMd)).toBe(imageMdx);
});

it('compiles user variables', () => {
const md = `Contact me at <<email>>`;

expect(mdx(mdastV6(md))).toBe(`Contact me at {user.email}\n`);
expect(migrate(md)).toBe(`Contact me at {user.email}\n`);
});

describe('<HTMLBlock> wrapping', () => {
Expand All @@ -224,8 +224,7 @@ This is an image: <img src="http://example.com/#\\>" >
`;

it('should wrap raw <style> tags in an <HTMLBlock>', async () => {
const legacyAST = mdastV6(rawStyle);
const converted = mdx(legacyAST);
const converted = migrate(rawStyle);
const compiled = compile(converted);
const Component = (await run(compiled)).default;
render(
Expand All @@ -237,8 +236,7 @@ This is an image: <img src="http://example.com/#\\>" >
});

it('should wrap raw <script> tags in an <HTMLBlock>', async () => {
const legacyAST = mdastV6(rawScript);
const converted = mdx(legacyAST);
const converted = migrate(rawScript);
const compiled = compile(converted);
const Component = (await run(compiled)).default;
render(
Expand All @@ -254,8 +252,7 @@ This is an image: <img src="http://example.com/#\\>" >
* @note compatability mode has been deprecated for RMDX
*/
const spy = vi.spyOn(console, 'log');
const legacyAST = mdastV6(magicScript);
const converted = mdx(legacyAST);
const converted = migrate(magicScript);
const compiled = compile(converted);
const Component = await run(compiled);
render(
Expand Down Expand Up @@ -286,7 +283,7 @@ This is an image: <img src="http://example.com/#\\>" >
[/block]
`;

const rmdx = mdx(mdastV6(md));
const rmdx = migrate(md);

expect(rmdx).toMatch('<Image align="center" width="250px" src="https://files.readme.io/4a1c7a0-Iphone.jpeg" />');
});
Expand All @@ -310,7 +307,7 @@ This is an image: <img src="http://example.com/#\\>" >
}
[/block]`;

const rmdx = mdx(mdastV6(md));
const rmdx = migrate(md);
expect(rmdx).toMatchInlineSnapshot(
`
"<Image alt="Data Plane Setup" align="center" border={true} src="https://files.readme.io/fd21f977cfbb9f55b3a13ab0b827525e94ee1576f21bbe82945cdc22cc966d82-Screenshot_2024-09-12_at_3.47.05_PM.png">
Expand All @@ -324,7 +321,7 @@ This is an image: <img src="http://example.com/#\\>" >
it('trims whitespace surrounding phrasing content (emphasis, strong, etc)', () => {
const md = `** bold ** and _ italic _ and *** bold italic ***`;

const rmdx = mdx(mdastV6(md));
const rmdx = migrate(md);
expect(rmdx).toMatchInlineSnapshot(`
"**bold** and *italic* and ***bold italic***
"
Expand All @@ -351,8 +348,7 @@ This is an image: <img src="http://example.com/#\\>" >
## Tile View
`;

const tree = mdastV6(md);
const rmdx = mdx(tree);
const rmdx = migrate(md);
expect(rmdx).toMatchInlineSnapshot(`
"![806](https://files.readme.io/9ac3bf4-SAP_Folders_Note.png "SAP Folders Note.png")

Expand Down Expand Up @@ -382,7 +378,7 @@ ${JSON.stringify(
[/block]
`;

const rmdx = mdx(mdastV6(md));
const rmdx = migrate(md);
expect(rmdx).toMatchInlineSnapshot(`
"<Table align={["left","left"]}>
<thead>
Expand Down Expand Up @@ -422,7 +418,7 @@ ${JSON.stringify(
> Lorem ipsum dolor sit amet consectetur adipisicing elit. Error eos animi obcaecati quod repudiandae aliquid nemo veritatis ex, quos delectus minus sit omnis vel dolores libero, recusandae ea dignissimos iure?
`;

const rmdx = mdx(mdastV6(md));
const rmdx = migrate(md);
expect(rmdx).toMatchInlineSnapshot(`
"> 🥈
>
Expand Down Expand Up @@ -452,7 +448,7 @@ ${JSON.stringify(
[/block]
`;

const rmdx = mdx(mdastV6(md));
const rmdx = migrate(md);
expect(rmdx).toMatchInlineSnapshot(`
"<Table align={["left","left"]}>
<thead>
Expand Down Expand Up @@ -491,7 +487,7 @@ ${JSON.stringify(
it('compiles inline html', () => {
const md = `Inline html: <small>_string_</small>`;

const rmdx = mdx(mdastV6(md));
const rmdx = migrate(md);
expect(rmdx).toMatchInlineSnapshot(`
"Inline html: <small>*string*</small>
"
Expand All @@ -501,7 +497,7 @@ ${JSON.stringify(
it('compiles tag-like syntax', () => {
const md = `Inline: <what even is this>`;

const rmdx = mdx(mdastV6(md));
const rmdx = migrate(md);
expect(rmdx).toMatchInlineSnapshot(`
"Inline: <what even is this>
"
Expand Down
8 changes: 4 additions & 4 deletions __tests__/migration/emphasis.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as rmdx from '../../index';
import { migrate } from '../../index';

describe('migrating emphasis', () => {
it('trims whitespace surrounding phrasing content (emphasis, strong, etc)', () => {
const md = '** bold ** and _ italic _ and *** bold italic ***';

const mdx = rmdx.mdx(rmdx.mdastV6(md));
const mdx = migrate(md);
expect(mdx).toMatchInlineSnapshot(`
"**bold** and *italic* and ***bold italic***
"
Expand All @@ -14,7 +14,7 @@ describe('migrating emphasis', () => {
it('moves whitespace surrounding phrasing content (emphasis, strong, etc) to the appropriate place', () => {
const md = '**bold **and also_ italic_ and*** bold italic***aaaaaah';

const mdx = rmdx.mdx(rmdx.mdastV6(md));
const mdx = migrate(md);
expect(mdx).toMatchInlineSnapshot(`
"**bold** and also *italic* and ***bold italic***aaaaaah
"
Expand All @@ -25,7 +25,7 @@ describe('migrating emphasis', () => {
const md =
'*the recommended initial action is to**initiate a [reversal operation (rollback)](https://docs.jupico.com/reference/ccrollback) test**. *';

const mdx = rmdx.mdx(rmdx.mdastV6(md));
const mdx = migrate(md);
expect(mdx).toMatchInlineSnapshot(`
"*the recommended initial action is to**initiate a [reversal operation (rollback)](https://docs.jupico.com/reference/ccrollback) test**.*
"
Expand Down
5 changes: 2 additions & 3 deletions __tests__/migration/html-comments.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as rmdx from '../../index';
import { migrate } from '../../index';

describe('migrating html comments', () => {
it('migrates escaped html comments', () => {
Expand All @@ -21,8 +21,7 @@ describe('migrating html comments', () => {
\\-->
`;

const ast = rmdx.mdastV6(md);
const mdx = rmdx.mdx(ast);
const mdx = migrate(md);
expect(mdx).toMatchInlineSnapshot(`
"{/*

Expand Down
19 changes: 19 additions & 0 deletions __tests__/migration/html-entities.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { migrate } from '../../index';

describe('migrating html entities', () => {
it('removes html entity spaces', () => {
const md = `
{
"json": true
}
`;
const mdx = migrate(md);

expect(mdx).toMatchInlineSnapshot(`
"\\{\\
"json": true\\
}
"
`);
});
});
5 changes: 2 additions & 3 deletions __tests__/migration/image.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as rmdx from '../../index';
import { migrate } from '../../index';

describe('migrating images', () => {
it('compiles images', () => {
Expand All @@ -20,8 +20,7 @@ describe('migrating images', () => {
[/block]
`;

const ast = rmdx.mdastV6(md);
const mdx = rmdx.mdx(ast);
const mdx = migrate(md);
expect(mdx).toMatchInlineSnapshot(`
"<Image align="center" className="border" border={true} src="https://fastly.picsum.photos/id/507/200/300.jpg?hmac=v0NKvUrOWTKZuZFmMlLN_7-RdRgeF-qFLeBGXpufxgg" />
"
Expand Down
8 changes: 3 additions & 5 deletions __tests__/migration/link-reference.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import * as rmdx from '../../index';
import { migrate } from '../../index';

describe('mdx migration of link references', () => {
it('compiles link references correctly', () => {
const md = '[wat_wat]';

const ast = rmdx.mdastV6(md);
const mdx = rmdx.mdx(ast);
const mdx = migrate(md);
expect(mdx).toMatchInlineSnapshot(`
"\\[wat\\_wat]
"
Expand All @@ -19,8 +18,7 @@ describe('mdx migration of link references', () => {
[wat_wat]: https://wat.com
`;

const ast = rmdx.mdastV6(md);
const mdx = rmdx.mdx(ast);
const mdx = migrate(md);
expect(mdx).toMatchInlineSnapshot(`
"[wat\\_wat][wat_wat]

Expand Down
11 changes: 5 additions & 6 deletions __tests__/migration/magic-block.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as rmdx from '../../index';
import { migrate } from '../../index';

describe('migrating magic blocks', () => {
it('compiles magic blocks without enough newlines', () => {
Expand Down Expand Up @@ -41,20 +41,19 @@ describe('migrating magic blocks', () => {
}
[/block]
`;
const ast = rmdx.mdastV6(md);
const mdx = rmdx.mdx(ast);
const mdx = migrate(md);
expect(mdx).toMatchInlineSnapshot(`
"## About cBEYONData

[ Overview of cBEYONData ](/docs/about-cbeyondata)&#x20;
[ Overview of cBEYONData ](/docs/about-cbeyondata)

## About CFO Control Control Tower

[Overview of CFO Control Tower](https://docs.cfocontroltower.com/docs/about-cfo-control-tower)&#x20;
[Overview of CFO Control Tower](https://docs.cfocontroltower.com/docs/about-cfo-control-tower)

> ❗️ CONFIDENTIAL
>
> *This documentation is confidential and proprietary information of cBEYONData LLC.*&#x20;
> *This documentation is confidential and proprietary information of cBEYONData LLC.*
"
`);
});
Expand Down
14 changes: 6 additions & 8 deletions __tests__/migration/tables.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as rmdx from '../../index';
import { migrate } from '../../index';

describe('mdx migration of tables', () => {
it('compiles tables with newlines and inline code', () => {
Expand All @@ -22,8 +22,7 @@ ${JSON.stringify(
[/block]
`;

const ast = rmdx.mdastV6(md);
const mdx = rmdx.mdx(ast);
const mdx = migrate(md);
expect(mdx).toMatchInlineSnapshot(`
"<Table align={["left","left"]}>
<thead>
Expand Down Expand Up @@ -81,7 +80,7 @@ ${JSON.stringify(
)}
[/block]
`;
const mdx = rmdx.mdx(rmdx.mdastV6(md));
const mdx = migrate(md);

expect(mdx).toMatchInlineSnapshot(`
"<Table align={["left","left"]}>
Expand Down Expand Up @@ -150,7 +149,7 @@ ${JSON.stringify(
)}
[/block]
`;
const mdx = rmdx.mdx(rmdx.mdastV6(md));
const mdx = migrate(md);

expect(mdx).toMatchInlineSnapshot(`
"<Table align={["left","left"]}>
Expand Down Expand Up @@ -237,8 +236,7 @@ ${JSON.stringify(
[/block]
`;

const ast = rmdx.mdastV6(md);
const mdx = rmdx.mdx(ast);
const mdx = migrate(md);
expect(mdx).toMatchInlineSnapshot(`
"<Table align={["left","left"]}>
<thead>
Expand Down Expand Up @@ -299,7 +297,7 @@ ${JSON.stringify(
)}
[/block]
`;
const mdx = rmdx.mdx(rmdx.mdastV6(md));
const mdx = migrate(md);

expect(mdx).toMatchInlineSnapshot(`
"<Table>
Expand Down
2 changes: 1 addition & 1 deletion index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ const utils = {
calloutIcons: {},
};

export { compile, hast, run, mdast, mdastV6, mdx, plain, remarkPlugins, tags } from './lib';
export { compile, hast, run, mdast, mdastV6, mdx, migrate, plain, remarkPlugins, tags } from './lib';
export { Components, utils };
Loading