Skip to content
Open
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
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,15 @@ https://youtu.be/dQw4w9WgXcQ

</details>

#### Options

All options should go under the `YouTube` namespace.

| name | Type | Required | Default | Description |
| :----- | :------- | :------- | :------ | :--------------------------- |
| height | `string` | ❌ | 100% | Height of the YouTube iframe |
| width | `string` | ❌ | 315 | Width of the YouTube iframe |

## Options

### customTransformers
Expand Down
13 changes: 12 additions & 1 deletion src/__tests__/transformers/YouTube.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,24 @@ cases(
);

test('Gets the correct YouTube iframe', async () => {
const html = await getHTML('https://youtu.be/dQw4w9WgXcQ');
const html = await getHTML('https://youtu.be/dQw4w9WgXcQ', {});

expect(html).toMatchInlineSnapshot(
`<iframe width="100%" height="315" src="https://www.youtube-nocookie.com/embed/dQw4w9WgXcQ?rel=0" frameBorder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowFullScreen></iframe>`
);
});

test('Gets the correct YouTube iframe with custom dimensions', async () => {
const html = await getHTML('https://youtu.be/dQw4w9WgXcQ', {
width: '50%',
height: '50%',
});

expect(html).toMatchInlineSnapshot(
`"<iframe width=\\"50%\\" height=\\"50%\\" src=\\"https://www.youtube-nocookie.com/embed/dQw4w9WgXcQ?rel=0\\" frameBorder=\\"0\\" allow=\\"accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture\\" allowFullScreen></iframe>"`
);
});

test('Plugin can transform YouTube links', async () => {
const markdownAST = getMarkdownASTForFile('YouTube');

Expand Down
6 changes: 4 additions & 2 deletions src/transformers/YouTube.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ export const getYouTubeIFrameSrc = (urlString) => {

return embedUrl.toString();
};
export const getHTML = (url) => {
export const getHTML = (url, { width = '100%', height = '315' }) => {
const iframeSrc = getYouTubeIFrameSrc(url);

return `<iframe width="100%" height="315" src="${iframeSrc}" frameBorder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowFullScreen></iframe>`;
return `<iframe width="${width}" height="${height}" src="${iframeSrc}" frameBorder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowFullScreen></iframe>`;
};

export const name = 'YouTube';