From 1acc6465345f4c19f5e387fbad51474e5c2b33e1 Mon Sep 17 00:00:00 2001 From: Achille Lacoin Date: Fri, 28 Jul 2023 16:55:40 +0200 Subject: [PATCH] feat: add support for val.town embeds (#6821) --- src/element/embeddable.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/element/embeddable.ts b/src/element/embeddable.ts index ecd149f6..08988b28 100644 --- a/src/element/embeddable.ts +++ b/src/element/embeddable.ts @@ -40,6 +40,9 @@ const RE_TWITTER = /(?:http(?:s)?:\/\/)?(?:(?:w){3}.)?twitter.com/; const RE_TWITTER_EMBED = /^$/i; @@ -53,6 +56,7 @@ const ALLOWED_DOMAINS = new Set([ "gist.github.com", "twitter.com", "stackblitz.com", + "val.town", ]); const createSrcDoc = (body: string) => { @@ -122,6 +126,14 @@ export const getEmbedLink = (link: string | null | undefined): EmbeddedLink => { return { link, aspectRatio, type }; } + const valLink = link.match(RE_VALTOWN); + if (valLink) { + link = + valLink[1] === "embed" ? valLink[0] : valLink[0].replace("/v", "/embed"); + embeddedLinkCache.set(originalLink, { link, aspectRatio, type }); + return { link, aspectRatio, type }; + } + if (RE_TWITTER.test(link)) { let ret: EmbeddedLink; // assume embed code