From 30c39d27f59306a137d17dfd273d5143be7702f1 Mon Sep 17 00:00:00 2001 From: Ren Amamiya <123083837+reyamir@users.noreply.github.com> Date: Sat, 6 May 2023 08:02:53 +0700 Subject: [PATCH] fix note parser --- src/app/note/components/parser.tsx | 13 ++++++++++--- src/app/note/components/preview/video.tsx | 5 ++++- src/app/note/components/rootNote.tsx | 11 ++++++++++- src/app/note/components/user/default.tsx | 2 +- src/app/note/components/user/repost.tsx | 2 +- 5 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/app/note/components/parser.tsx b/src/app/note/components/parser.tsx index b90bba58..f11125c2 100644 --- a/src/app/note/components/parser.tsx +++ b/src/app/note/components/parser.tsx @@ -23,16 +23,16 @@ export const noteParser = (event: Event) => { // make sure url is trimmed const url = item.trim(); - if (url.match(/\.(jpg|jpeg|gif|png|webp|avif)$/gim)) { + if (url.match(/\.(jpg|jpeg|gif|png|webp|avif)$/i)) { // image url content.images.push(url); // remove url from original content - content.parsed = content.parsed.replace(url, ''); + content.parsed = content.parsed.toString().replace(url, ''); } else if (url.match(/\.(mp4|webm|mov)$/i)) { // video content.videos.push(url); // remove url from original content - content.parsed = content.parsed.replace(url, ''); + content.parsed = content.parsed.toString().replace(url, ''); } else { content.parsed = reactStringReplace(content.parsed, url, () => { return ( @@ -65,5 +65,12 @@ export const noteParser = (event: Event) => { } }); + // remove extra spaces + content.parsed.forEach((item, index) => { + if (typeof item === 'string') { + content.parsed[index] = item.replace(/\s{2,}/g, ' '); + } + }); + return content; }; diff --git a/src/app/note/components/preview/video.tsx b/src/app/note/components/preview/video.tsx index 9607649e..3cdfc180 100644 --- a/src/app/note/components/preview/video.tsx +++ b/src/app/note/components/preview/video.tsx @@ -2,7 +2,10 @@ import { MediaOutlet, MediaPlayer } from '@vidstack/react'; export default function VideoPreview({ urls }: { urls: string[] }) { return ( -