diff --git a/packages/@atjson/source-html/src/converter/social-embeds.ts b/packages/@atjson/source-html/src/converter/social-embeds.ts index 45502acb7..a44eb9556 100644 --- a/packages/@atjson/source-html/src/converter/social-embeds.ts +++ b/packages/@atjson/source-html/src/converter/social-embeds.ts @@ -268,6 +268,11 @@ export default function (doc: Document) { attributes: { ...attributes, content: content.id, + hidePostCaption: + blockquote.attributes.dataset["instgrm-captioned"] != null && + blockquote.attributes.dataset["instgrm-captioned"] !== "false" + ? undefined + : true, }, }), content, diff --git a/packages/@atjson/source-html/test/instagram-embed.test.ts b/packages/@atjson/source-html/test/instagram-embed.test.ts index 3c1c3abd1..4f7282a01 100644 --- a/packages/@atjson/source-html/test/instagram-embed.test.ts +++ b/packages/@atjson/source-html/test/instagram-embed.test.ts @@ -67,6 +67,71 @@ describe("InstagramEmbed", () => { `); }); + test("v12 with no caption", () => { + let doc = HTMLSource.fromRaw( + `
View this post on Instagram

A cartoon by David Borchart. #NewYorkerCartoons

A post shared by The New Yorker Cartoons (@newyorkercartoons) on

` + ).convertTo(OffsetSource); + + expect(serialize(doc, { withStableIds: true })).toMatchInlineSnapshot(` + { + "blocks": [ + { + "attributes": { + "content": "M00000000", + "hidePostCaption": true, + "url": "https://www.instagram.com/p/CEmnm85D_UQ", + }, + "id": "B00000000", + "parents": [], + "selfClosing": false, + "type": "instagram-embed", + }, + { + "attributes": {}, + "id": "B00000001", + "parents": [ + "instagram-embed", + ], + "selfClosing": false, + "type": "text", + }, + { + "attributes": {}, + "id": "B00000002", + "parents": [ + "instagram-embed", + "text", + ], + "selfClosing": true, + "type": "line-break", + }, + ], + "marks": [ + { + "attributes": { + "refs": [ + "B00000000", + ], + }, + "id": "M00000000", + "range": "(1..143]", + "type": "slice", + }, + { + "attributes": { + "target": "_blank", + "url": "https://www.instagram.com/newyorkercartoons/?utm_source=ig_embed&utm_campaign=loading", + }, + "id": "M00000001", + "range": "(68..92)", + "type": "link", + }, + ], + "text": "A cartoon by David Borchart. #NewYorkerCartoons A post shared by The New Yorker Cartoons (@newyorkercartoons) on Sep 1, 2020 at 11:08am PDT", + } + `); + }); + test("v14", () => { let doc = HTMLSource.fromRaw( `
View this post on Instagram

A post shared by NASA (@nasa)

` @@ -112,6 +177,52 @@ describe("InstagramEmbed", () => { `); }); + test("v14 with no caption", () => { + let doc = HTMLSource.fromRaw( + `
View this post on Instagram

A post shared by NASA (@nasa)

` + ).convertTo(OffsetSource); + + expect(serialize(doc, { withStableIds: true })).toMatchInlineSnapshot(` + { + "blocks": [ + { + "attributes": { + "content": "M00000000", + "hidePostCaption": true, + "url": "https://www.instagram.com/p/Bg15hWbn_Zj", + }, + "id": "B00000000", + "parents": [], + "selfClosing": false, + "type": "instagram-embed", + }, + { + "attributes": {}, + "id": "B00000001", + "parents": [ + "instagram-embed", + ], + "selfClosing": false, + "type": "text", + }, + ], + "marks": [ + { + "attributes": { + "refs": [ + "B00000000", + ], + }, + "id": "M00000000", + "range": "(1..31]", + "type": "slice", + }, + ], + "text": "A post shared by NASA (@nasa)", + } + `); + }); + test("tv", () => { let doc = HTMLSource.fromRaw( `
View this post on Instagram

We are in this together, we will get through it together. Let’s imagine together. Sing with us ❤ All love to you, from me and my dear friends. #WeAreOne ....... #KristenWiig #JamieDornan @labrinth @james_marsden @sarahkatesilverman @eddiebenjamin @jimmyfallon @natalieportman @zoeisabellakravitz @siamusic @reallyndacarter @amyadams @leslieodomjr @pascalispunk @chrisodowd @hotpatooties #WillFerrell @markruffalo @norahjones @ashleybenson @kaiagerber @caradelevingne @anniemumolo @princesstagramslam

A post shared by Gal Gadot (@gal_gadot) on

` @@ -176,6 +287,71 @@ describe("InstagramEmbed", () => { `); }); + test("tv with no caption", () => { + let doc = HTMLSource.fromRaw( + `
View this post on Instagram

We are in this together, we will get through it together. Let’s imagine together. Sing with us ❤ All love to you, from me and my dear friends. #WeAreOne ....... #KristenWiig #JamieDornan @labrinth @james_marsden @sarahkatesilverman @eddiebenjamin @jimmyfallon @natalieportman @zoeisabellakravitz @siamusic @reallyndacarter @amyadams @leslieodomjr @pascalispunk @chrisodowd @hotpatooties #WillFerrell @markruffalo @norahjones @ashleybenson @kaiagerber @caradelevingne @anniemumolo @princesstagramslam

A post shared by Gal Gadot (@gal_gadot) on

` + ).convertTo(OffsetSource); + + expect(serialize(doc, { withStableIds: true })).toMatchInlineSnapshot(` + { + "blocks": [ + { + "attributes": { + "content": "M00000000", + "hidePostCaption": true, + "url": "https://www.instagram.com/tv/B95M4kNhbzz", + }, + "id": "B00000000", + "parents": [], + "selfClosing": false, + "type": "instagram-embed", + }, + { + "attributes": {}, + "id": "B00000001", + "parents": [ + "instagram-embed", + ], + "selfClosing": false, + "type": "text", + }, + { + "attributes": {}, + "id": "B00000002", + "parents": [ + "instagram-embed", + "text", + ], + "selfClosing": true, + "type": "line-break", + }, + ], + "marks": [ + { + "attributes": { + "refs": [ + "B00000000", + ], + }, + "id": "M00000000", + "range": "(1..573]", + "type": "slice", + }, + { + "attributes": { + "target": "_blank", + "url": "https://www.instagram.com/gal_gadot/?utm_source=ig_embed&utm_campaign=loading", + }, + "id": "M00000001", + "range": "(520..530)", + "type": "link", + }, + ], + "text": "We are in this together, we will get through it together. Let’s imagine together. Sing with us ❤ All love to you, from me and my dear friends. #WeAreOne ....... #KristenWiig #JamieDornan @labrinth @james_marsden @sarahkatesilverman @eddiebenjamin @jimmyfallon @natalieportman @zoeisabellakravitz @siamusic @reallyndacarter @amyadams @leslieodomjr @pascalispunk @chrisodowd @hotpatooties #WillFerrell @markruffalo @norahjones @ashleybenson @kaiagerber @caradelevingne @anniemumolo @princesstagramslam A post shared by Gal Gadot (@gal_gadot) on Mar 18, 2020 at 4:49pm PDT", + } + `); + }); + test("reel", () => { let doc = HTMLSource.fromRaw( `
View this post on Instagram

A post shared by Instagram (@instagram)

` @@ -220,4 +396,50 @@ describe("InstagramEmbed", () => { } `); }); + + test("reel with no caption", () => { + let doc = HTMLSource.fromRaw( + `
View this post on Instagram

A post shared by Instagram (@instagram)

` + ).convertTo(OffsetSource); + + expect(serialize(doc, { withStableIds: true })).toMatchInlineSnapshot(` + { + "blocks": [ + { + "attributes": { + "content": "M00000000", + "hidePostCaption": true, + "url": "https://www.instagram.com/reel/CDt37vzFw3f", + }, + "id": "B00000000", + "parents": [], + "selfClosing": false, + "type": "instagram-embed", + }, + { + "attributes": {}, + "id": "B00000001", + "parents": [ + "instagram-embed", + ], + "selfClosing": false, + "type": "text", + }, + ], + "marks": [ + { + "attributes": { + "refs": [ + "B00000000", + ], + }, + "id": "M00000000", + "range": "(1..41]", + "type": "slice", + }, + ], + "text": "A post shared by Instagram (@instagram)", + } + `); + }); });