Skip to content

Commit

Permalink
Fix: #90 블록내 개행문자 삽입되는 문제 해결 (#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
Seok93 authored Aug 29, 2024
1 parent f17eb52 commit a5b61e4
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/components/common/CustomMarkdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,25 @@ const component: Partial<Components> = {
};

function getChangedMarkdownForLineBreak(markdown: string) {
return markdown
.split('\n')
.map((sentence) => (sentence === '' ? '\n<br />\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<br/>\n');
} else {
resultLines.push(line);
}
});

return resultLines.join('\n');
}

export default function CustomMarkdown({ markdown }: CustomMarkdownProps) {
Expand Down

0 comments on commit a5b61e4

Please sign in to comment.