Skip to content

Commit

Permalink
feat: support giphy.com embed domain (excalidraw#7192)
Browse files Browse the repository at this point in the history
  • Loading branch information
dwelle authored Oct 25, 2023
1 parent 0f81c30 commit d1f8eec
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/element/embeddable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -60,6 +63,7 @@ const ALLOWED_DOMAINS = new Set([
"*.simplepdf.eu",
"stackblitz.com",
"val.town",
"giphy.com",
]);

const createSrcDoc = (body: string) => {
Expand Down Expand Up @@ -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];
Expand Down

0 comments on commit d1f8eec

Please sign in to comment.