From 2ecc877968c073562bf1ba2adce7e5435fb3915d Mon Sep 17 00:00:00 2001 From: plebbitor Date: Fri, 21 Apr 2023 16:57:08 +0200 Subject: [PATCH] fixed markdown double newlines --- src/App.js | 11 +++++++++++ src/components/Post.jsx | 20 +++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/App.js b/src/App.js index 5c00d29f..b960d4b5 100644 --- a/src/App.js +++ b/src/App.js @@ -41,6 +41,17 @@ const GlobalStyle = createGlobalStyle` .line-break { white-space: pre-line; } + + .custom-paragraph { + margin: 0; + padding: 0; + } + + .custom-linebreak { + display: block; + margin: 0; + padding: 0; + } `; const StyledContainer = styled(ToastContainer)` diff --git a/src/components/Post.jsx b/src/components/Post.jsx index 66359c48..9903c064 100644 --- a/src/components/Post.jsx +++ b/src/components/Post.jsx @@ -3,6 +3,22 @@ import ReactMarkdown from 'react-markdown'; import { Link } from 'react-router-dom'; import DOMPurify from 'dompurify'; +const removeExtraNewlines = () => (tree) => { + let lastNodeWasNewline = false; + tree.children = tree.children.filter((node) => { + if (node.type === 'br') { + if (lastNodeWasNewline) { + return false; + } + lastNodeWasNewline = true; + } else { + lastNodeWasNewline = false; + } + return true; + }); +}; + + const blockquoteToGreentext = () => (tree) => { tree.children.forEach((node) => { if (node.type === 'blockquote') { @@ -56,12 +72,14 @@ const Post = ({ content, handlequoteclick, comment }) => { return ( null, video: () => null, source: () => null, gif: () => null, + p: ({ children }) =>
{children}
, + br: () =>
, }} className='line-break' />