diff --git a/src/components/markdown/markdown.tsx b/src/components/markdown/markdown.tsx index e36e8810..4d7d72f1 100644 --- a/src/components/markdown/markdown.tsx +++ b/src/components/markdown/markdown.tsx @@ -1,6 +1,7 @@ import React, { useEffect, useMemo, useRef, useState } from 'react'; import { useTranslation } from 'react-i18next'; import ReactMarkdown from 'react-markdown'; +import remarkBreaks from 'remark-breaks'; import remarkGfm from 'remark-gfm'; import supersub from 'remark-supersub'; import rehypeSanitize, { defaultSchema } from 'rehype-sanitize'; @@ -128,7 +129,7 @@ interface MarkdownProps { } const Markdown = ({ content, title }: MarkdownProps) => { - const remarkPlugins: any[] = [[supersub]]; + const remarkPlugins: any[] = [[remarkBreaks, supersub]]; if (content && content.length <= MAX_LENGTH_FOR_GFM) { remarkPlugins.push([remarkGfm, { singleTilde: false }]); @@ -150,6 +151,14 @@ const Markdown = ({ content, title }: MarkdownProps) => { const isInCatalogView = isCatalogView(useLocation().pathname, useParams()); + // retain empty lines + const processedContent = useMemo(() => { + let md = content; + md = md.replace(/```[\s\S]*?```/g, (m) => m.replace(/\n/g, '\n ')); + md = md.replace(/(?<=\n\n)(?![*-])\n/g, ' \n '); + return md; + }, [content]); + return ( {isInCatalogView && title && ( @@ -159,7 +168,7 @@ const Markdown = ({ content, title }: MarkdownProps) => { )} void; postCid: wrap='soft' ref={textRef} onChange={(e) => { - const content = e.target.value.replace(/\n/g, '\n\n'); + const content = e.target.value; isInPostView ? setPublishReplyOptions({ content }) : setSubmitStore({ content }); }} /> diff --git a/src/components/reply-modal/reply-modal.tsx b/src/components/reply-modal/reply-modal.tsx index 57cf1e6f..6dcc06b4 100644 --- a/src/components/reply-modal/reply-modal.tsx +++ b/src/components/reply-modal/reply-modal.tsx @@ -154,7 +154,7 @@ const ReplyModal = ({ closeModal, showReplyModal, parentCid, postCid, scrollY, s }; const handleContentChange = (e: React.ChangeEvent) => { - const contentWithoutPrefix = e.target.value.slice(contentPrefix.length).replace(/\n/g, '\n\n'); + const contentWithoutPrefix = e.target.value.slice(contentPrefix.length); if (textRef.current && textRef.current.value !== contentWithoutPrefix) { setPublishReplyOptions({ content: contentWithoutPrefix }); }