Skip to content

Commit

Permalink
[수정] 포스트잇 | markdown 줄바꿈 되지 않는 문제 해결
Browse files Browse the repository at this point in the history
1. 정규식을 이용하여 포스트잇 내용에 대한 문자열을 검사한다.
2. 개행문자 앞에 태그가 없을 경우 해당 개행문자를 <br/> 태그로 치환한다.
- 모든 개행문자를 <br/>로 단순 치환할 경우 태그 다음에 존재하는
  개행문자까지 변환되어 줄 간격이 지나치게 벌어지는 문제가 생기기 때문.

fixed #5
  • Loading branch information
yj-oh committed Nov 24, 2021
1 parent ba9a832 commit 8bac002
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/components/PostIt.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@
return list.filter(postIt => postIt.id !== id);
});
}
function convertMarkdownToHtml(markdown) {
const html = marked(markdown);
return html.replaceAll(/(?<!\<(.*)\>)\n/gm, '<br/>');
}
</script>

<article
Expand Down Expand Up @@ -201,7 +206,7 @@
>{content}</textarea>
{:else}
<div class='content' on:click={toggleEditContent}>
<div>{@html marked(content)}</div>
<div>{@html convertMarkdownToHtml(content)}</div>
</div>
{/if}
</div>
Expand Down

0 comments on commit 8bac002

Please sign in to comment.