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
15 changes: 12 additions & 3 deletions src/__tests__/transformers/CodePen.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import cases from 'jest-in-case';

import plugin from '../../';
import { getHTML, shouldTransform } from '../../transformers/CodePen';

import { cache, getMarkdownASTForFile, mdastToHtml } from '../helpers';

cases(
Expand Down Expand Up @@ -79,13 +77,24 @@ cases(
);

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

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

test('Gets the correct CodePen iframe with custom dimensions', () => {
const html = getHTML('https://codepen.io/team/codepen/pen/PNaGbb', {
width: '50%',
height: '50%',
});

expect(html).toMatchInlineSnapshot(
`<iframe src="https://codepen.io/team/codepen/embed/preview/PNaGbb" style="width:50%; height:50%;"></iframe>`
);
});

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

Expand Down
4 changes: 2 additions & 2 deletions src/transformers/CodePen.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ export const shouldTransform = (url) => {
);
};

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

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