From 9d8a0e5ce54a41488f2a002f5ceb807670d92faa Mon Sep 17 00:00:00 2001 From: kirk1027 Date: Wed, 17 Jan 2024 14:24:18 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=A1=E3=83=A2=E3=83=AA=E3=82=B9=E3=83=88?= =?UTF-8?q?=E3=81=AE=E3=82=B3=E3=83=B3=E3=83=86=E3=83=B3=E3=83=84=E3=81=AE?= =?UTF-8?q?HTML=E3=82=BF=E3=82=B0=E3=82=92=E5=89=8A=E9=99=A4=E3=81=97?= =?UTF-8?q?=E3=81=BE=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/MemoList.tsx | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/pages/MemoList.tsx b/src/pages/MemoList.tsx index d35509f..24305e1 100644 --- a/src/pages/MemoList.tsx +++ b/src/pages/MemoList.tsx @@ -100,6 +100,16 @@ export function MemoList(): JSX.Element { } }; + const removeHtmlTags = (htmlString: string): string => { + // 新しい行で
タグを置き換える + const newlineRegex = //gi; + htmlString = htmlString.replace(newlineRegex, ' '); + + // DOMParserを使用してHTML文字列からHTMLタグを取り除く + const doc = new DOMParser().parseFromString(htmlString, 'text/html'); + return doc.body.textContent || ""; + }; + useEffect(() => { getMemoList(); }, [loginUser, getMemoList]); @@ -189,7 +199,7 @@ export function MemoList(): JSX.Element { const [reorderedItem] = items.splice(result.source.index, 1); items.splice(result.destination.index, 0, reorderedItem); - setMemoList(items); + setMemoList(items); }; @@ -336,7 +346,7 @@ export function MemoList(): JSX.Element { width: '80%', display: 'inline-block' // インライン要素でも幅を適用させる }}> - {truncateText(memo.content, 100)} + {truncateText(removeHtmlTags(memo.content), 100)} }