Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add github service #91

Merged
merged 8 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from 6 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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Tool uses Editor.js pasted patterns handling and inserts iframe with embedded co
- [Coub](https://coub.com) — `coub` service
- [CodePen](https://codepen.io) — `codepen` service
- [Pinterest](https://www.pinterest.com) - `pinterest` service
- [GitHub Gist](https://gist.github.com) - `github` service
- 👇 Any other [customized service](#add-more-services)


Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@editorjs/embed",
"version": "2.5.1",
"version": "2.6.0",
"keywords": [
"codex editor",
"embed",
Expand Down
10 changes: 9 additions & 1 deletion src/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,5 +164,13 @@ export default {
regex: /https:\/\/miro.com\/\S+(\S{12})\/(\S+)?/,
embedUrl: 'https://miro.com/app/live-embed/<%= remote_id %>',
html: '<iframe width="700" height="500" style="margin: 0 auto;" allowFullScreen frameBorder="0" scrolling="no"></iframe>',
}
},
github: {
regex: /https?:\/\/gist.github.com\/([^\/\?\&]*)\/([^\/\?\&]*)/,
embedUrl: 'data:text/html;charset=utf-8,<head><base target="_blank" /></head><body><script src="https://gist.github.com/<%= remote_id %>" ></script></body>',
html: '<iframe width="100%" height="350" frameborder="0" style="margin: 0 auto;"></iframe>',
height: 300,
width: 600,
id: (groups) => `${groups.join('/')}.js`,
},
};
26 changes: 26 additions & 0 deletions test/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,32 @@ describe('Services Regexps', () => {
});
});

it('Github', async () => {
const service = 'github';

const urls = [
{
source: 'https://gist.github.com/userharis/091b56505c804276e1f91925976f11db',
embed: 'data:text/html;charset=utf-8,<head><base target="_blank" /></head><body><script src="https://gist.github.com/userharis/091b56505c804276e1f91925976f11db.js" ></script></body>',
},
{
source: 'https://gist.github.com/userharis/a8c2977094d4716c43e35e6c20b7d306',
embed: 'data:text/html;charset=utf-8,<head><base target="_blank" /></head><body><script src="https://gist.github.com/userharis/a8c2977094d4716c43e35e6c20b7d306.js" ></script></body>',
},
];

urls.forEach(url => {
expect(patterns[service].test(url.source)).to.be.true;

const event = composePasteEventMock('pattern', service, url.source);

embed.onPaste(event);

expect(embed.data.service).to.be.equal(service);
expect(embed.data.embed).to.be.equal(url.embed);
expect(embed.data.source).to.be.equal(url.source);
});
});
});

describe('Miro service', () => {
Expand Down