From d1f8eec1744bc995d3513b82352344c3897b7a78 Mon Sep 17 00:00:00 2001 From: David Luzar Date: Thu, 26 Oct 2023 00:00:50 +0200 Subject: [PATCH] feat: support giphy.com embed domain (#7192) --- src/element/embeddable.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/element/embeddable.ts b/src/element/embeddable.ts index 615fb99a..29aac1bc 100644 --- a/src/element/embeddable.ts +++ b/src/element/embeddable.ts @@ -48,6 +48,9 @@ const RE_VALTOWN = const RE_GENERIC_EMBED = /^<(?:iframe|blockquote)[\s\S]*?\s(?:src|href)=["']([^"']*)["'][\s\S]*?>$/i; +const RE_GIPHY = + /giphy.com\/(?:clips|embed|gifs)\/[a-zA-Z0-9]*?-?([a-zA-Z0-9]+)(?:[^a-zA-Z0-9]|$)/; + const ALLOWED_DOMAINS = new Set([ "youtube.com", "youtu.be", @@ -60,6 +63,7 @@ const ALLOWED_DOMAINS = new Set([ "*.simplepdf.eu", "stackblitz.com", "val.town", + "giphy.com", ]); const createSrcDoc = (body: string) => { @@ -309,6 +313,10 @@ export const extractSrc = (htmlString: string): string => { return gistMatch[1]; } + if (RE_GIPHY.test(htmlString)) { + return `https://giphy.com/embed/${RE_GIPHY.exec(htmlString)![1]}`; + } + const match = htmlString.match(RE_GENERIC_EMBED); if (match && match.length === 2) { return match[1];