From c5cb4d5f9c8d18dbbef2cff44c0fc48269c77bcf Mon Sep 17 00:00:00 2001 From: Sean McNamara Date: Thu, 29 Oct 2020 11:42:58 +0000 Subject: [PATCH 1/3] feat(YouTube): Adds support for passing width and height of Youtube videos --- src/__tests__/transformers/YouTube.js | 13 ++++++++++++- src/transformers/YouTube.js | 4 ++-- 2 files changed, 14 insertions(+), 3 deletions(-) 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..ad84902e 100644 --- a/src/transformers/YouTube.js +++ b/src/transformers/YouTube.js @@ -45,8 +45,8 @@ 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 ``; }; From 7377197cceba6cf430457f4b8b819978947106a7 Mon Sep 17 00:00:00 2001 From: Sean McNamara Date: Thu, 29 Oct 2020 13:20:58 +0000 Subject: [PATCH 2/3] feat(YouTube): Export Youtube transformer name so data passed in service config comes through. --- src/transformers/YouTube.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/transformers/YouTube.js b/src/transformers/YouTube.js index ad84902e..2ef2e371 100644 --- a/src/transformers/YouTube.js +++ b/src/transformers/YouTube.js @@ -50,3 +50,5 @@ export const getHTML = (url, { width = '100%', height = '315' }) => { return ``; }; + +export const name = 'YouTube'; From 816d3b2488d09df554018d0efb952fd8b9c6ccf2 Mon Sep 17 00:00:00 2001 From: Sean McNamara Date: Thu, 29 Oct 2020 13:31:37 +0000 Subject: [PATCH 3/3] feat(YouTube): Adds documentation for YouTube options --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) 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