From 04a6f7dbdc789cf968e6177b80f766f519a5e160 Mon Sep 17 00:00:00 2001 From: blazh Date: Mon, 9 Sep 2024 13:53:32 +0200 Subject: [PATCH] bugfix: tweets not rendering when they are paragraph element --- .../_pages/Contest/components/Prompt/Proposal/index.tsx | 5 ++--- packages/react-app-revamp/helpers/isContentTweet.ts | 7 ++++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/react-app-revamp/components/_pages/Contest/components/Prompt/Proposal/index.tsx b/packages/react-app-revamp/components/_pages/Contest/components/Prompt/Proposal/index.tsx index 40133be37..e42586bbd 100644 --- a/packages/react-app-revamp/components/_pages/Contest/components/Prompt/Proposal/index.tsx +++ b/packages/react-app-revamp/components/_pages/Contest/components/Prompt/Proposal/index.tsx @@ -29,9 +29,8 @@ interface ContestProposalProps { const transform = (node: HTMLElement): ReactNode => { const element = node.tagName.toLowerCase(); - - if (element === "a") { - const href = node.getAttribute("href"); + if (element === "a" || element === "p") { + const href = element === "a" ? node.getAttribute("href") : node.textContent; const tweetUrlMatch = href && href.match(twitterRegex); const isInsideList = diff --git a/packages/react-app-revamp/helpers/isContentTweet.ts b/packages/react-app-revamp/helpers/isContentTweet.ts index 21951918e..748cc1bbf 100644 --- a/packages/react-app-revamp/helpers/isContentTweet.ts +++ b/packages/react-app-revamp/helpers/isContentTweet.ts @@ -11,9 +11,10 @@ export const isContentTweet = (htmlContent: string): Tweet => { let foundTweet = false; let tweetId = ""; - $("a").each(function () { - const href = $(this).attr("href"); - const tweetUrlMatch = href && href.match(twitterRegex); + $("a, p").each(function () { + const element = this.tagName.toLowerCase(); + const content = element === "a" ? $(this).attr("href") : $(this).text(); + const tweetUrlMatch = content && content.match(twitterRegex); const isInsideList = $(this).parents("li,ul,ol").length > 0;