diff --git a/README.md b/README.md index 650acb97..483d8951 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,7 @@ Tool uses Editor.js pasted patterns handling and inserts iframe with embedded co - [CodePen](https://codepen.io) — `codepen` service - [Pinterest](https://www.pinterest.com) - `pinterest` service - [GitHub Gist](https://gist.github.com) - `github` service +- [Reddit](https://www.reddit.com/) - `reddit` service - 👇 Any other [customized service](#add-more-services) diff --git a/package.json b/package.json index c1087c17..bb63bbc7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@editorjs/embed", - "version": "2.7.6", + "version": "2.7.7", "keywords": [ "codex editor", "embed", diff --git a/src/services.ts b/src/services.ts index 27e8e9c2..9bc5e49a 100644 --- a/src/services.ts +++ b/src/services.ts @@ -147,6 +147,15 @@ const SERVICES: ServicesConfigType = { width: 600, id: ids => ids[1], }, + reddit: { + regex: /https:\/\/www\.reddit\.com\/(.*)/, + embedUrl: + "https://www.redditmedia.com/<%= remote_id %>?ref_source=embed&ref=share&embed=true", + html: "", + width: 600, + height: 300, + id: (ids) => ids[0], + }, pinterest: { regex: /https?:\/\/([^\/\?\&]*).pinterest.com\/pin\/([^\/\?\&]*)\/?$/, embedUrl: 'https://assets.pinterest.com/ext/embed.html?id=<%= remote_id %>', diff --git a/test/services.ts b/test/services.ts index 1685d840..6072671a 100644 --- a/test/services.ts +++ b/test/services.ts @@ -322,6 +322,37 @@ describe('Services Regexps', () => { expect(embed.data.source).to.be.equal(url.source); }); }); + + it('Reddit', async () => { + const service = 'reddit'; + + const urls = [ + { + source: "https://www.reddit.com/r/news/comments/1g5b240/liam_payne_former_one_direction_member_dead_at_31/?utm_source=share&utm_medium=web3x&utm_name=web3xcss&utm_term=1&utm_content=share_button", + embed: "https://www.redditmedia.com/r/news/comments/1g5b240/liam_payne_former_one_direction_member_dead_at_31/?utm_source=share&utm_medium=web3x&utm_name=web3xcss&utm_term=1&utm_content=share_button?ref_source=embed&ref=share&embed=true" + }, + { + source: "https://www.reddit.com/r/news/comments/1fvdajx/comment/lq6aokl/?utm_source=share&utm_medium=web3x&utm_name=web3xcss&utm_term=1&utm_content=share_button", + embed: "https://www.redditmedia.com/r/news/comments/1fvdajx/comment/lq6aokl/?utm_source=share&utm_medium=web3x&utm_name=web3xcss&utm_term=1&utm_content=share_button?ref_source=embed&ref=share&embed=true" + }, + { + source: "https://www.reddit.com/r/news/comments/1fvdajx/central_pa_school_district_installs_surveillance/", + embed: "https://www.redditmedia.com/r/news/comments/1fvdajx/central_pa_school_district_installs_surveillance/?ref_source=embed&ref=share&embed=true" + }, + ]; + + 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); + }); + }); it('Aparat', async () => { const service = 'aparat'; const urls = [