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
18 changes: 17 additions & 1 deletion __tests__/compilers.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { mdast, mdx } from '../index';
import { mdast, mdx, mix } from '../index';

describe('ReadMe Flavored Blocks', () => {
it('Embed', () => {
Expand All @@ -15,3 +15,19 @@ describe('ReadMe Flavored Blocks', () => {
`);
});
});

describe('mix ReadMe Flavored Blocks', () => {
it.skip('Embed', () => {
const txt = '[Embedded meta links.](https://nyti.me/s/gzoa2xb2v3 "@embed")';
const ast = mdast(txt);
const out = mix(ast);
expect(out).toMatchSnapshot();
});

it.skip('Emojis', () => {
expect(mix(mdast(':smiley:'))).toMatchInlineSnapshot(`
":smiley:
"
`);
});
});
157 changes: 156 additions & 1 deletion __tests__/compilers/callout.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Root } from 'mdast';

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

describe('callouts compiler', () => {
it('compiles callouts', () => {
Expand Down Expand Up @@ -156,3 +156,158 @@ describe('callouts compiler', () => {
expect(mdx(mockAst as Root).trim()).toBe(markdown);
});
});

describe('mix callout compiler', () => {
it.skip('compiles callouts', () => {
const markdown = `> 🚧 It works!
>
> And, it no longer deletes your content!
`;

expect(mix(mdast(markdown))).toBe(markdown);
});

it.skip('compiles callouts with no heading', () => {
const markdown = `> 🚧
>
> And, it no longer deletes your content!
`;

expect(mix(mdast(markdown))).toBe(markdown);
});

it.skip('compiles callouts with no heading or body', () => {
const markdown = `> 🚧
`;

expect(mix(mdast(markdown))).toBe(markdown);
});

it.skip('compiles callouts with no heading or body and no new line at the end', () => {
const markdown = '> ℹ️';

expect(mix(mdast(markdown))).toBe(`${markdown}\n`);
});

it.skip('compiles callouts with markdown in the heading', () => {
const markdown = `> 🚧 It **works**!
>
> And, it no longer deletes your content!
`;

expect(mix(mdast(markdown))).toBe(markdown);
});

it.skip('compiles callouts with paragraphs', () => {
const markdown = `> 🚧 It **works**!
>
> And...
>
> it correctly compiles paragraphs. :grimace:
`;

expect(mix(mdast(markdown))).toBe(markdown);
});

it.skip('compiles callouts with icons + theme', () => {
const mockAst = {
type: 'root',
children: [
{
children: [
{
type: 'paragraph',
children: [
{
type: 'text',
value: 'test',
},
],
},
],
type: 'rdme-callout',
data: {
hName: 'Callout',
hProperties: {
icon: 'fad fa-wagon-covered',
empty: false,
theme: 'warn',
},
},
},
],
};
const markdown = `
<Callout icon="fad fa-wagon-covered" theme="warn">
test
</Callout>`.trim();

expect(mix(mockAst as Root).trim()).toBe(markdown);
});

it.skip('compiles a callout with only a theme set', () => {
const mockAst = {
type: 'root',
children: [
{
children: [
{
type: 'heading',
depth: 3,
children: [
{
type: 'text',
value: 'test',
},
],
},
],
type: 'rdme-callout',
data: {
hName: 'Callout',
hProperties: {
empty: false,
theme: 'warn',
},
},
},
],
};
const markdown = '> 🚧 test';

expect(mix(mockAst as Root).trim()).toBe(markdown);
});

it.skip('compiles a callout with only an icon set', () => {
const mockAst = {
type: 'root',
children: [
{
children: [
{
type: 'heading',
depth: 3,
children: [
{
type: 'text',
value: 'test',
},
],
},
],
type: 'rdme-callout',
data: {
hName: 'Callout',
hProperties: {
icon: '🚧',
empty: false,
},
},
},
],
};
const markdown = '> 🚧 test';

expect(mix(mockAst as Root).trim()).toBe(markdown);
});
});
44 changes: 43 additions & 1 deletion __tests__/compilers/code-tabs.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { mdast, mdx } from '../../index';
import { mdast, mdx, mix } from '../../index';

describe('code-tabs compiler', () => {
it('compiles code tabs', () => {
Expand Down Expand Up @@ -41,3 +41,45 @@ I should stay here
expect(mdx(mdast(markdown))).toBe(markdown);
});
});

describe('mix code-tabs compiler', () => {
it.skip('compiles code tabs', () => {
const markdown = `\`\`\`
const works = true;
\`\`\`
\`\`\`
const cool = true;
\`\`\`
`;

expect(mix(mdast(markdown))).toBe(markdown);
});

it.skip('compiles code tabs with metadata', () => {
const markdown = `\`\`\`js Testing
const works = true;
\`\`\`
\`\`\`js
const cool = true;
\`\`\`
`;

expect(mix(mdast(markdown))).toBe(markdown);
});

it.skip("doesnt't mess with joining other blocks", () => {
const markdown = `\`\`\`
const works = true;
\`\`\`
\`\`\`
const cool = true;
\`\`\`

## Hello!

I should stay here
`;

expect(mix(mdast(markdown))).toBe(markdown);
});
});
119 changes: 117 additions & 2 deletions __tests__/compilers/compatability.test.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import fs from 'node:fs';

import { render, screen } from '@testing-library/react';
import React from 'react';

import { vi } from 'vitest';

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

describe('compatability with RDMD', () => {
Expand Down Expand Up @@ -507,3 +506,119 @@ ${JSON.stringify(
`);
});
});

describe('mix compatability with RDMD', () => {
it.skip('compiles glossary nodes', () => {
const ast = {
type: 'readme-glossary-item',
data: {
hProperties: {
term: 'parliament',
},
},
};

expect(mix(ast).trim()).toBe('<Glossary>parliament</Glossary>');
});

it.skip('compiles mdx glossary nodes', () => {
const ast = {
type: 'readme-glossary-item',
data: {
hName: 'Glossary',
},
children: [{ type: 'text', value: 'parliament' }],
};

expect(mix(ast).trim()).toBe('<Glossary>parliament</Glossary>');
});

it.skip('compiles mdx image nodes', () => {
const ast = {
type: 'root',
children: [
{
type: 'figure',
data: { hName: 'figure' },
children: [
{
align: 'center',
width: '300px',
src: 'https://drastik.ch/wp-content/uploads/2023/06/blackcat.gif',
url: 'https://drastik.ch/wp-content/uploads/2023/06/blackcat.gif',
alt: '',
title: '',
type: 'image',
data: {
hProperties: {
align: 'center',
className: 'border',
width: '300px',
},
},
},
{
type: 'figcaption',
data: { hName: 'figcaption' },
children: [
{
type: 'paragraph',
children: [
{ type: 'text', value: 'hello ' },
{ type: 'strong', children: [{ type: 'text', value: 'cat' }] },
],
},
],
},
],
},
],
};

expect(mix(ast).trim()).toMatchInlineSnapshot(`
"<Image align="center" width="300px" src="https://drastik.ch/wp-content/uploads/2023/06/blackcat.gif" border={true}>
hello **cat**
</Image>"
`);
});

it.skip('compiles mdx embed nodes', () => {
const ast = {
data: {
hProperties: {
html: false,
url: 'https://cdn.shopify.com/s/files/1/0711/5132/1403/files/BRK0502-034178M.pdf',
title: 'iframe',
href: 'https://cdn.shopify.com/s/files/1/0711/5132/1403/files/BRK0502-034178M.pdf',
typeOfEmbed: 'iframe',
height: '300px',
width: '100%',
iframe: true,
},
hName: 'embed',
html: false,
url: 'https://cdn.shopify.com/s/files/1/0711/5132/1403/files/BRK0502-034178M.pdf',
title: 'iframe',
href: 'https://cdn.shopify.com/s/files/1/0711/5132/1403/files/BRK0502-034178M.pdf',
typeOfEmbed: 'iframe',
height: '300px',
width: '100%',
iframe: true,
},
type: 'embed',
};

expect(mix(ast).trim()).toBe(
'<Embed url="https://cdn.shopify.com/s/files/1/0711/5132/1403/files/BRK0502-034178M.pdf" title="iframe" href="https://cdn.shopify.com/s/files/1/0711/5132/1403/files/BRK0502-034178M.pdf" typeOfEmbed="iframe" height="300px" width="100%" iframe="true" />',
);
});

it.skip('compiles reusable-content nodes', () => {
const ast = {
type: 'reusable-content',
tag: 'Parliament',
};

expect(mix(ast).trim()).toBe('<Parliament />');
});
});
10 changes: 9 additions & 1 deletion __tests__/compilers/escape.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { mdast, mdx } from '../../index';
import { mdast, mdx, mix } from '../../index';

describe('escape compiler', () => {
it('handles escapes', () => {
Expand All @@ -7,3 +7,11 @@ describe('escape compiler', () => {
expect(mdx(mdast(txt))).toBe('\\&para;\n');
});
});

describe('mix escape compiler', () => {
it.skip('handles escapes', () => {
const txt = '\\&para;';

expect(mix(mdast(txt))).toBe('\\&para;\n');
});
});
Loading