Skip to content

Commit

Permalink
Merge branch 'beta' into fix/widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
kellyjosephprice committed May 21, 2024
2 parents bb664ce + 2347ac2 commit 9f98afd
Show file tree
Hide file tree
Showing 34 changed files with 344 additions and 350 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
Changelog
===

## Version 6.75.0-beta.34

### ✨ New & Improved

* embeds! ([#878](https://github.com/readmeio/markdown/issues/878)) ([9dee309](https://github.com/readmeio/markdown/commit/9dee30984b10411016e625eba1f4bfe8b26e4233))

## Version 6.75.0-beta.33

### 🛠 Fixes & Updates

* dynamic import ([06a22ba](https://github.com/readmeio/markdown/commit/06a22bac10e95788f6703c174a1ab22b84697f9e))

## Version 6.75.0-beta.32

### ✨ New & Improved
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`ReadMe Flavored Blocks > Embed 1`] = `
"[Embedded meta links.](https://nyti.me/s/gzoa2xb2v3 "@nyt")
"[Embedded meta links.](https://nyti.me/s/gzoa2xb2v3 "@embed")
"
`;
2 changes: 1 addition & 1 deletion __tests__/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -345,4 +345,4 @@ exports[`list items 1`] = `
exports[`prefix anchors with "section-" > should add a section- prefix to heading anchors 1`] = `undefined`;
exports[`tables 1`] = `"<div class=\\"rdmd-table\\"><div class=\\"rdmd-table-inner\\"><table><thead><tr><th>Tables</th><th style=\\"text-align: center;\\">Are</th><th style=\\"text-align: right;\\">Cool</th></tr></thead><tbody><tr><td>col 3 is</td><td style=\\"text-align: center;\\">right-aligned</td><td style=\\"text-align: right;\\">$1600</td></tr><tr><td>col 2 is</td><td style=\\"text-align: center;\\">centered</td><td style=\\"text-align: right;\\">$12</td></tr><tr><td>zebra stripes</td><td style=\\"text-align: center;\\">are neat</td><td style=\\"text-align: right;\\">$1</td></tr></tbody></table></div></div>"`;
exports[`tables 1`] = `"<div class="rdmd-table"><div class="rdmd-table-inner"><table><thead><tr><th>Tables</th><th style="text-align: center;">Are</th><th style="text-align: right;">Cool</th></tr></thead><tbody><tr><td>col 3 is</td><td style="text-align: center;">right-aligned</td><td style="text-align: right;">$1600</td></tr><tr><td>col 2 is</td><td style="text-align: center;">centered</td><td style="text-align: right;">$12</td></tr><tr><td>zebra stripes</td><td style="text-align: center;">are neat</td><td style="text-align: right;">$1</td></tr></tbody></table></div></div>"`;
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion __tests__/browser/markdown.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('visual regression tests', () => {
// 'callouts',
'calloutTests',
'codeBlocks',
// 'embeds',
'embeds',
//'features',
// 'headings',
'images',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { mdast, mdx } from '../index';

describe('ReadMe Flavored Blocks', () => {
it('Embed', () => {
const txt = '[Embedded meta links.](https://nyti.me/s/gzoa2xb2v3 "@nyt")';
const txt = '[Embedded meta links.](https://nyti.me/s/gzoa2xb2v3 "@embed")';
const ast = mdast(txt);
const out = mdx(ast);
expect(out).toMatchSnapshot();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@ import React from 'react';

import Callout from '../../components/Callout';

describe.skip('Callout', () => {
describe('Callout', () => {
it('render _all_ its children', () => {
render(
<Callout title="Title">
<Callout title="Title" icon="icon" theme="theme">
<p>Title</p>
<p>First Paragraph</p>
<p>Second Paragraph</p>
</Callout>
</Callout>,
);

expect(screen.getByText('Second Paragraph')).toBeVisible();
});
});
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import React from 'react';
import { vi } from 'vitest';

import CreateCode from '../../components/Code';
import Code from '../../components/Code';

const { fireEvent, render, screen } = require('@testing-library/react');
const copy = require('copy-to-clipboard');
import { fireEvent, render, screen } from '@testing-library/react';
import copy from 'copy-to-clipboard';

const Code = CreateCode({ attributes: {} }, { copyButtons: true });
const codeProps = {
copyButtons: true,
};

vi.mock('@readme/syntax-highlighter', () => ({
default: code => {
Expand All @@ -16,27 +18,27 @@ vi.mock('@readme/syntax-highlighter', () => ({
}));

describe.skip('Code', () => {
it('copies the variable interpolated code', () => {
it.skip('copies the variable interpolated code', () => {
const props = {
children: ['console.log("<<name>>");'],
};

const { container } = render(<Code {...props} />);
const { container } = render(<Code {...codeProps} {...props} />);

expect(container).toHaveTextContent(/VARIABLE_SUBSTITUTED/);
fireEvent.click(screen.getByRole('button'));

expect(copy).toHaveBeenCalledWith(expect.stringMatching(/VARIABLE_SUBSTITUTED/));
});

it('does not nest the button inside the code block', () => {
render(<Code>{'console.log("hi");'}</Code>);
it.skip('does not nest the button inside the code block', () => {
render(<Code {...codeProps}>{'console.log("hi");'}</Code>);
const btn = screen.getByRole('button');

expect(btn.parentNode.nodeName.toLowerCase()).not.toBe('code');
expect(btn.parentNode?.nodeName.toLowerCase()).not.toBe('code');
});

it('allows undefined children?!', () => {
it.skip('allows undefined children?!', () => {
const { container } = render(<Code />);

expect(container).toHaveTextContent('');
Expand Down
16 changes: 0 additions & 16 deletions __tests__/components/CodeTabs.test.jsx

This file was deleted.

21 changes: 21 additions & 0 deletions __tests__/components/CodeTabs.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { render } from '@testing-library/react';
import React from 'react';
import { compile, run } from '../../index';

describe('CodeTabs', () => {
it('render _all_ its children', async () => {
const md = `
\`\`\`
assert('theme', 'dark');
\`\`\`
\`\`\`
assert('theme', 'light');
\`\`\`
`;
const Component = await run(compile(md));
const { container } = render(<Component />);

expect(container).toHaveTextContent(`assert('theme', 'dark')`);
expect(container).toHaveTextContent(`assert('theme', 'light')`);
});
});
File renamed without changes.
8 changes: 8 additions & 0 deletions __tests__/components/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,12 @@

exports[`Components > Callout 1`] = `"<blockquote class="callout callout_error" theme="❗️"><h3 class="callout-heading"><span class="callout-icon">❗️</span><p>Error Callout</p></h3><p>Lorem ipsum dolor.</p></blockquote>"`;

exports[`Components > Embed 1`] = `"<div class="embed embed_hasImg"><div class="embed-media"><iframe class="embedly-embed" src="//cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.google.com%2Fmaps%2Fembed%2Fv1%2Fplace%3Fcenter%3D37.829698%252C-122.258166%26key%3DAIzaSyD9HrlRuI1Ani0-MTZ7pvzxwxi4pgW0BCY%26zoom%3D16%26q%3D4126%2BOpal%2BSt%2C%2BOakland%2C%2BCA%2B94609&amp;display_name=Google+Maps&amp;url=https%3A%2F%2Fwww.google.com%2Fmaps%2Fplace%2F4126%2BOpal%2BSt%2C%2BOakland%2C%2BCA%2B94609%2F%4037.829698%2C-122.258166%2C16z%2Fdata%3D%214m5%213m4%211s0x80857dfb145a04ff%3A0x96b17d967421636f%218m2%213d37.8296978%214d-122.2581661%3Fhl%3Den&amp;image=http%3A%2F%2Fmaps-api-ssl.google.com%2Fmaps%2Fapi%2Fstaticmap%3Fcenter%3D37.829698%2C-122.258166%26zoom%3D15%26size%3D250x250%26sensor%3Dfalse&amp;key=02466f963b9b4bb8845a05b53d3235d7&amp;type=text%2Fhtml&amp;schema=google" width="600" height="450" scrolling="no" title="Google Maps embed" frameborder="0" allow="autoplay; fullscreen" allowfullscreen="true"></iframe></div></div>"`;

exports[`Components > Embed 2`] = `"<iframe height="550" src="https://consent-manager.metomic.io/placeholder-demo.html?example=reddit" style="display: flex; margin: auto;"></iframe>"`;

exports[`Components > Embed 3`] = `"<div class="embed embed_hasImg"><a class="embed-link" href="https://www.nytimes.com/2020/05/03/us/politics/george-w-bush-coronavirus-unity.html" rel="noopener noreferrer" target="_blank"><img alt="George W. Bush Calls for End to Pandemic Partisanship" class="embed-img" loading="lazy" src="https://static01.nyt.com/images/2020/05/02/world/02dc-virus-bush-2/merlin_171999921_e857a690-fb9b-462d-a20c-28c8161107c9-facebookJumbo.jpg"><div class="embed-body"><img alt="nytimes.com" height="14" src="https://www.nytimes.com/vi-assets/static-assets/favicon-4bf96cb6a1093748bf5b3c429accb9b4.ico" width="14"><small class="embed-provider">nytimes.com</small><div class="embed-title">George W. Bush Calls for End to Pandemic Partisanship</div></div></a></div>"`;
exports[`Components > Embed 4`] = `"<p><a href="https://www.nytimes.com/2020/05/03/us/politics/george-w-bush-coronavirus-unity.html" title="@embed">rdmd</a></p>"`;
exports[`Components > Image 1`] = `"<p><span aria-label="Bro eats pizza and makes an OK gesture." class="img lightbox closed" role="button" tabindex="0"><span class="lightbox-inner"><img src="https://files.readme.io/6f52e22-man-eating-pizza-and-making-an-ok-gesture.jpg" width="auto" height="auto" title="Pizza Face" class="img img-align- " alt="Bro eats pizza and makes an OK gesture." loading="eager"></span></span></p>"`;
67 changes: 28 additions & 39 deletions __tests__/components/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import { vi } from 'vitest';

import { compile, run, utils } from '../../index';

import { silenceConsole } from '../helpers';

describe.skip('Data Replacements', () => {
it('Variables', () => {
const { container } = render(
Expand Down Expand Up @@ -87,46 +85,37 @@ describe('Components', () => {
expect(container.querySelectorAll('pre')[1]).toHaveClass('CodeTabs_active');
});

it.skip('Embed', () => {
it('Embed', () => {
const fixtures = {
html: `[block:embed]
{
"html": "<iframe class=\\"embedly-embed\\" src=\\"//cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.google.com%2Fmaps%2Fembed%2Fv1%2Fplace%3Fcenter%3D37.829698%252C-122.258166%26key%3DAIzaSyD9HrlRuI1Ani0-MTZ7pvzxwxi4pgW0BCY%26zoom%3D16%26q%3D4126%2BOpal%2BSt%2C%2BOakland%2C%2BCA%2B94609&display_name=Google+Maps&url=https%3A%2F%2Fwww.google.com%2Fmaps%2Fplace%2F4126%2BOpal%2BSt%2C%2BOakland%2C%2BCA%2B94609%2F%4037.829698%2C-122.258166%2C16z%2Fdata%3D%214m5%213m4%211s0x80857dfb145a04ff%3A0x96b17d967421636f%218m2%213d37.8296978%214d-122.2581661%3Fhl%3Den&image=http%3A%2F%2Fmaps-api-ssl.google.com%2Fmaps%2Fapi%2Fstaticmap%3Fcenter%3D37.829698%2C-122.258166%26zoom%3D15%26size%3D250x250%26sensor%3Dfalse&key=02466f963b9b4bb8845a05b53d3235d7&type=text%2Fhtml&schema=google\\" width=\\"600\\" height=\\"450\\" scrolling=\\"no\\" title=\\"Google Maps embed\\" frameborder=\\"0\\" allow=\\"autoplay; fullscreen\\" allowfullscreen=\\"true\\"></iframe>",
"url": "https://www.google.com/maps/place/4126+Opal+St,+Oakland,+CA+94609/@37.829698,-122.258166,16z/data=!4m5!3m4!1s0x80857dfb145a04ff:0x96b17d967421636f!8m2!3d37.8296978!4d-122.2581661?hl=en",
"title": "4126 Opal St, Oakland, CA 94609",
"favicon": "https://www.google.com/images/branding/product/ico/maps15_bnuw3a_32dp.ico",
"image": "http://maps-api-ssl.google.com/maps/api/staticmap?center=37.829698,-122.258166&zoom=15&size=250x250&sensor=false"
}
[/block]`,
iframe: `[block:embed]
{
"html": false,
"url": "https://consent-manager.metomic.io/placeholder-demo.html?example=reddit",
"title": null,
"favicon": null,
"iframe": true,
"height": "550"
}
[/block]`,
meta: `[block:embed]
{
"html": false,
"url": "https://www.nytimes.com/2020/05/03/us/politics/george-w-bush-coronavirus-unity.html",
"title": "George W. Bush Calls for End to Pandemic Partisanship",
"favicon": "https://www.nytimes.com/vi-assets/static-assets/favicon-4bf96cb6a1093748bf5b3c429accb9b4.ico",
"image": "https://static01.nyt.com/images/2020/05/02/world/02dc-virus-bush-2/merlin_171999921_e857a690-fb9b-462d-a20c-28c8161107c9-facebookJumbo.jpg"
}
[/block]`,
rdmd: '[](https://www.nytimes.com/2020/05/03/us/politics/george-w-bush-coronavirus-unity.html "@embed")',
html: `<Embed
html='<iframe class="embedly-embed" src="//cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.google.com%2Fmaps%2Fembed%2Fv1%2Fplace%3Fcenter%3D37.829698%252C-122.258166%26key%3DAIzaSyD9HrlRuI1Ani0-MTZ7pvzxwxi4pgW0BCY%26zoom%3D16%26q%3D4126%2BOpal%2BSt%2C%2BOakland%2C%2BCA%2B94609&display_name=Google+Maps&url=https%3A%2F%2Fwww.google.com%2Fmaps%2Fplace%2F4126%2BOpal%2BSt%2C%2BOakland%2C%2BCA%2B94609%2F%4037.829698%2C-122.258166%2C16z%2Fdata%3D%214m5%213m4%211s0x80857dfb145a04ff%3A0x96b17d967421636f%218m2%213d37.8296978%214d-122.2581661%3Fhl%3Den&image=http%3A%2F%2Fmaps-api-ssl.google.com%2Fmaps%2Fapi%2Fstaticmap%3Fcenter%3D37.829698%2C-122.258166%26zoom%3D15%26size%3D250x250%26sensor%3Dfalse&key=02466f963b9b4bb8845a05b53d3235d7&type=text%2Fhtml&schema=google" width="600" height="450" scrolling="no" title="Google Maps embed" frameborder="0" allow="autoplay; fullscreen" allowfullscreen="true"></iframe>'
url="https://www.google.com/maps/place/4126+Opal+St,+Oakland,+CA+94609/@37.829698,-122.258166,16z/data=!4m5!3m4!1s0x80857dfb145a04ff:0x96b17d967421636f!8m2!3d37.8296978!4d-122.2581661?hl=en"
title="4126 Opal St, Oakland, CA 94609"
favicon="https://www.google.com/images/branding/product/ico/maps15_bnuw3a_32dp.ico"
image="http://maps-api-ssl.google.com/maps/api/staticmap?center=37.829698,-122.258166&zoom=15&size=250x250&sensor=false"
/>`,
iframe: `<Embed
html={false}
url="https://consent-manager.metomic.io/placeholder-demo.html?example=reddit"
title={null}
favicon={null}
iframe={true}
height="550"
/>`,
meta: `<Embed
html={false}
url="https://www.nytimes.com/2020/05/03/us/politics/george-w-bush-coronavirus-unity.html"
title="George W. Bush Calls for End to Pandemic Partisanship"
favicon="https://www.nytimes.com/vi-assets/static-assets/favicon-4bf96cb6a1093748bf5b3c429accb9b4.ico"
image="https://static01.nyt.com/images/2020/05/02/world/02dc-virus-bush-2/merlin_171999921_e857a690-fb9b-462d-a20c-28c8161107c9-facebookJumbo.jpg"
/>`,
rdmd: '[rdmd](https://www.nytimes.com/2020/05/03/us/politics/george-w-bush-coronavirus-unity.html "@embed")',
};

silenceConsole()(error => {
Object.values(fixtures).map(fx => {
const { container } = render(compile(fx));
return expect(container.innerHTML).toMatchSnapshot();
});

expect(error).toHaveBeenCalledTimes(1);
Object.values(fixtures).map(async fx => {
const component = await run(compile(fx));
const { container } = render(React.createElement(component));
return expect(container.innerHTML).toMatchSnapshot();
});
});

Expand Down
13 changes: 0 additions & 13 deletions __tests__/helpers.js

This file was deleted.

17 changes: 17 additions & 0 deletions __tests__/helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { vi } from 'vitest';

const silenceConsole =
(prop: keyof Console = 'error', impl = () => {}) =>
fn => {
let spy;

try {
spy = vi.spyOn(console, prop).mockImplementation(impl);

return fn(spy);
} finally {
spy.mockRestore();
}
};

export { silenceConsole };
13 changes: 7 additions & 6 deletions __tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ test.skip('check list items', () => {
expect(container.innerHTML).toMatchSnapshot();
});

test.skip('gemoji generation', () => {
const { container } = render(run(compile(':sparkles:')));
test('gemoji generation', async () => {
const component = await run(compile(':sparkles:'));
const { container } = render(React.createElement(component));
expect(container.querySelector('.lightbox')).not.toBeInTheDocument();
});

Expand All @@ -65,17 +66,17 @@ test.skip('should strip out inputs', () => {
expect(screen.queryByRole('input')).not.toBeInTheDocument();
});

test.skip('tables', () => {
const { container } = render(
run(
test('tables', async () => {
const component = await run(
compile(`| Tables | Are | Cool |
| ------------- |:-------------:| -----:|
| col 3 is | right-aligned | $1600 |
| col 2 is | centered | $12 |
| zebra stripes | are neat | $1 |
`)
)
);

const { container } = render(React.createElement(component));

expect(container.innerHTML.trim()).toMatchSnapshot();
});
Expand Down
2 changes: 1 addition & 1 deletion components/Callout/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';

interface Props extends React.PropsWithChildren<React.HTMLAttributes<HTMLQuoteElement>> {
attributes: {};
attributes?: {};
icon: string;
theme?: string;
heading?: React.ReactElement;
Expand Down
13 changes: 7 additions & 6 deletions components/Code/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ let syntaxHighlighter;
let canonicalLanguage = _ => '';

if (typeof window !== 'undefined') {
const module = await import('@readme/syntax-highlighter');

syntaxHighlighter = module.default;
canonicalLanguage = module.canonical;
import('@readme/syntax-highlighter').then(module => {
syntaxHighlighter = module.default;
canonicalLanguage = module.canonical;
});
}

function CopyCode({ codeRef, rootClass = 'rdmd-code-copy', className = '' }) {
Expand All @@ -32,15 +32,16 @@ function CopyCode({ codeRef, rootClass = 'rdmd-code-copy', className = '' }) {
return <button ref={button} aria-label="Copy Code" className={`${rootClass} ${className}`} onClick={copier} />;
}

interface Props extends Omit<HTMLElement, 'lang'> {
interface CodeProps {
children?: string[] | string;
copyButtons?: boolean;
lang?: string;
meta?: string;
theme?: string;
value?: string;
}

const Code = (props: Props) => {
const Code = (props: CodeProps) => {
const { children, copyButtons, lang, theme, value } = props;

const language = canonicalLanguage(lang);
Expand Down
Loading

0 comments on commit 9f98afd

Please sign in to comment.