diff --git a/README.md b/README.md index e7a5e307..5c5b6792 100644 --- a/README.md +++ b/README.md @@ -767,6 +767,15 @@ https://youtu.be/dQw4w9WgXcQ +#### 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 diff --git a/src/__tests__/transformers/YouTube.js b/src/__tests__/transformers/YouTube.js index 2843aec9..ad4cee71 100644 --- a/src/__tests__/transformers/YouTube.js +++ b/src/__tests__/transformers/YouTube.js @@ -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( `` ); }); +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( + `""` + ); +}); + test('Plugin can transform YouTube links', async () => { const markdownAST = getMarkdownASTForFile('YouTube'); diff --git a/src/transformers/YouTube.js b/src/transformers/YouTube.js index 8f3ba343..2ef2e371 100644 --- a/src/transformers/YouTube.js +++ b/src/transformers/YouTube.js @@ -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 ``; + return ``; }; + +export const name = 'YouTube';