fix markdown with remark-breaks

This commit is contained in:
plebbitor
2023-04-23 18:53:47 +02:00
parent 183bd11d34
commit 8338974b45
3 changed files with 12 additions and 75 deletions
+2 -18
View File
@@ -2,21 +2,7 @@ import React from 'react';
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;
});
};
import breaks from 'remark-breaks';
const blockquoteToGreentext = () => (tree) => {
@@ -72,16 +58,14 @@ const Post = ({ content, handlequoteclick, comment }) => {
return (
<ReactMarkdown
children={sanitizedContent}
remarkPlugins={[blockquoteToGreentext, removeExtraNewlines]}
remarkPlugins={[blockquoteToGreentext, breaks]}
components={{
img: () => null,
video: () => null,
source: () => null,
gif: () => null,
p: ({ children }) => <div className="custom-paragraph">{children}</div>,
br: () => <br className="custom-linebreak" />,
}}
className='line-break'
/>
);
};