Skip to content

Commit fbac3f9

Browse files
committed
feat(CodePen): add support for height & width options
1 parent 6f0f7d1 commit fbac3f9

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

src/__tests__/transformers/CodePen.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import cases from 'jest-in-case';
2-
32
import plugin from '../../';
43
import { getHTML, shouldTransform } from '../../transformers/CodePen';
5-
64
import { cache, getMarkdownASTForFile, mdastToHtml } from '../helpers';
75

86
cases(
@@ -79,13 +77,24 @@ cases(
7977
);
8078

8179
test('Gets the correct CodePen iframe', () => {
82-
const html = getHTML('https://codepen.io/team/codepen/pen/PNaGbb');
80+
const html = getHTML('https://codepen.io/team/codepen/pen/PNaGbb', {});
8381

8482
expect(html).toMatchInlineSnapshot(
8583
`<iframe src="https://codepen.io/team/codepen/embed/preview/PNaGbb" style="width:100%; height:300px;"></iframe>`
8684
);
8785
});
8886

87+
test('Gets the correct CodePen iframe with custom dimensions', () => {
88+
const html = getHTML('https://codepen.io/team/codepen/pen/PNaGbb', {
89+
width: '50%',
90+
height: '50%',
91+
});
92+
93+
expect(html).toMatchInlineSnapshot(
94+
`<iframe src="https://codepen.io/team/codepen/embed/preview/PNaGbb" style="width:50%; height:50%;"></iframe>`
95+
);
96+
});
97+
8998
test('Plugin can transform CodePen links', async () => {
9099
const markdownAST = getMarkdownASTForFile('CodePen');
91100

src/transformers/CodePen.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ export const shouldTransform = (url) => {
77
);
88
};
99

10-
export const getHTML = (url) => {
10+
export const getHTML = (url, { width = '100%', height = '300px' }) => {
1111
const iframeUrl = url.replace('/pen/', '/embed/preview/');
1212

13-
return `<iframe src="${iframeUrl}" style="width:100%; height:300px;"></iframe>`;
13+
return `<iframe src="${iframeUrl}" style="width:${width}; height:${height};"></iframe>`;
1414
};

0 commit comments

Comments
 (0)