Skip to content

Commit c5cb4d5

Browse files
seanmcnMichaelDeBoey
authored andcommitted
feat(YouTube): Adds support for passing width and height of Youtube videos
1 parent 668d719 commit c5cb4d5

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/__tests__/transformers/YouTube.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,24 @@ cases(
138138
);
139139

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

143143
expect(html).toMatchInlineSnapshot(
144144
`<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>`
145145
);
146146
});
147147

148+
test('Gets the correct YouTube iframe with custom dimensions', async () => {
149+
const html = await getHTML('https://youtu.be/dQw4w9WgXcQ', {
150+
width: '50%',
151+
height: '50%',
152+
});
153+
154+
expect(html).toMatchInlineSnapshot(
155+
`"<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>"`
156+
);
157+
});
158+
148159
test('Plugin can transform YouTube links', async () => {
149160
const markdownAST = getMarkdownASTForFile('YouTube');
150161

src/transformers/YouTube.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ export const getYouTubeIFrameSrc = (urlString) => {
4545

4646
return embedUrl.toString();
4747
};
48-
export const getHTML = (url) => {
48+
export const getHTML = (url, { width = '100%', height = '315' }) => {
4949
const iframeSrc = getYouTubeIFrameSrc(url);
5050

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

0 commit comments

Comments
 (0)