From a5b61e4f7c7689cebad54cfed7755f378cbc24c0 Mon Sep 17 00:00:00 2001 From: Suk Woo Date: Thu, 29 Aug 2024 22:48:50 +0900 Subject: [PATCH] =?UTF-8?q?Fix:=20#90=20=EB=B8=94=EB=A1=9D=EB=82=B4=20?= =?UTF-8?q?=EA=B0=9C=ED=96=89=EB=AC=B8=EC=9E=90=20=EC=82=BD=EC=9E=85?= =?UTF-8?q?=EB=90=98=EB=8A=94=20=EB=AC=B8=EC=A0=9C=20=ED=95=B4=EA=B2=B0=20?= =?UTF-8?q?(#96)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/common/CustomMarkdown.tsx | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/components/common/CustomMarkdown.tsx b/src/components/common/CustomMarkdown.tsx index f9373f22..2bee201e 100644 --- a/src/components/common/CustomMarkdown.tsx +++ b/src/components/common/CustomMarkdown.tsx @@ -137,10 +137,25 @@ const component: Partial = { }; function getChangedMarkdownForLineBreak(markdown: string) { - return markdown - .split('\n') - .map((sentence) => (sentence === '' ? '\n
\n' : sentence)) - .join('\n'); + const lines = markdown.split('\n'); + + let inCodeBlock = false; + const resultLines: string[] = []; + lines.forEach((line) => { + if (line.trim().startsWith('```')) { + inCodeBlock = !inCodeBlock; + resultLines.push(line); + return; + } + + if (!inCodeBlock && line.trim() === '') { + resultLines.push('\n
\n'); + } else { + resultLines.push(line); + } + }); + + return resultLines.join('\n'); } export default function CustomMarkdown({ markdown }: CustomMarkdownProps) {