mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fixed markdown double newlines
This commit is contained in:
+11
@@ -41,6 +41,17 @@ const GlobalStyle = createGlobalStyle`
|
|||||||
.line-break {
|
.line-break {
|
||||||
white-space: pre-line;
|
white-space: pre-line;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.custom-paragraph {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.custom-linebreak {
|
||||||
|
display: block;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const StyledContainer = styled(ToastContainer)`
|
const StyledContainer = styled(ToastContainer)`
|
||||||
|
|||||||
+19
-1
@@ -3,6 +3,22 @@ import ReactMarkdown from 'react-markdown';
|
|||||||
import { Link } from 'react-router-dom';
|
import { Link } from 'react-router-dom';
|
||||||
import DOMPurify from 'dompurify';
|
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) => {
|
const blockquoteToGreentext = () => (tree) => {
|
||||||
tree.children.forEach((node) => {
|
tree.children.forEach((node) => {
|
||||||
if (node.type === 'blockquote') {
|
if (node.type === 'blockquote') {
|
||||||
@@ -56,12 +72,14 @@ const Post = ({ content, handlequoteclick, comment }) => {
|
|||||||
return (
|
return (
|
||||||
<ReactMarkdown
|
<ReactMarkdown
|
||||||
children={sanitizedContent}
|
children={sanitizedContent}
|
||||||
remarkPlugins={[blockquoteToGreentext]}
|
remarkPlugins={[blockquoteToGreentext, removeExtraNewlines]}
|
||||||
components={{
|
components={{
|
||||||
img: () => null,
|
img: () => null,
|
||||||
video: () => null,
|
video: () => null,
|
||||||
source: () => null,
|
source: () => null,
|
||||||
gif: () => null,
|
gif: () => null,
|
||||||
|
p: ({ children }) => <div className="custom-paragraph">{children}</div>,
|
||||||
|
br: () => <br className="custom-linebreak" />,
|
||||||
}}
|
}}
|
||||||
className='line-break'
|
className='line-break'
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in New Issue
Block a user