Browse Source

feat: support giphy.com embed domain (#7192)

David Luzar 1 year ago
parent
commit
d1f8eec174
1 changed files with 8 additions and 0 deletions
  1. 8 0
      src/element/embeddable.ts

+ 8 - 0
src/element/embeddable.ts

@@ -48,6 +48,9 @@ const RE_VALTOWN =
 const RE_GENERIC_EMBED =
 const RE_GENERIC_EMBED =
   /^<(?:iframe|blockquote)[\s\S]*?\s(?:src|href)=["']([^"']*)["'][\s\S]*?>$/i;
   /^<(?: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([
 const ALLOWED_DOMAINS = new Set([
   "youtube.com",
   "youtube.com",
   "youtu.be",
   "youtu.be",
@@ -60,6 +63,7 @@ const ALLOWED_DOMAINS = new Set([
   "*.simplepdf.eu",
   "*.simplepdf.eu",
   "stackblitz.com",
   "stackblitz.com",
   "val.town",
   "val.town",
+  "giphy.com",
 ]);
 ]);
 
 
 const createSrcDoc = (body: string) => {
 const createSrcDoc = (body: string) => {
@@ -309,6 +313,10 @@ export const extractSrc = (htmlString: string): string => {
     return gistMatch[1];
     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);
   const match = htmlString.match(RE_GENERIC_EMBED);
   if (match && match.length === 2) {
   if (match && match.length === 2) {
     return match[1];
     return match[1];