mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
removed markdown
This commit is contained in:
+12
-65
@@ -1,73 +1,20 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import ReactMarkdown from 'react-markdown';
|
|
||||||
import { Link } from 'react-router-dom';
|
|
||||||
import DOMPurify from 'dompurify';
|
import DOMPurify from 'dompurify';
|
||||||
|
|
||||||
const blockquoteToGreentext = () => (tree) => {
|
const Post = ({ content }) => {
|
||||||
tree.children.forEach((node) => {
|
|
||||||
if (node.type === 'blockquote') {
|
|
||||||
node.children.forEach((child) => {
|
|
||||||
if (child.type === 'paragraph' && child.children.length > 0) {
|
|
||||||
const prefix = {
|
|
||||||
type: 'text',
|
|
||||||
value: '>',
|
|
||||||
};
|
|
||||||
child.children.unshift(prefix);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
node.type = 'div';
|
|
||||||
node.data = {
|
|
||||||
hName: 'div',
|
|
||||||
hProperties: {
|
|
||||||
className: 'greentext',
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const createQuotelink = (handlequoteclick, comment, children) => {
|
|
||||||
const text = children.map((child) => (typeof child === 'string' ? child : child.props.children)).join('');
|
|
||||||
const regex = /(\s|^)(c\/[A-Za-z0-9]{12}|c\/[A-Za-z0-9]{45})(?=\s|$)/g;
|
|
||||||
const parts = text.split(regex);
|
|
||||||
|
|
||||||
return parts.flatMap((part, i) => {
|
|
||||||
if (regex.test(part)) {
|
|
||||||
return [
|
|
||||||
<Link
|
|
||||||
key={`link-${i}`}
|
|
||||||
className="quotelink"
|
|
||||||
to=""
|
|
||||||
onClick={handlequoteclick}
|
|
||||||
>
|
|
||||||
{part.trim()}
|
|
||||||
</Link>,
|
|
||||||
];
|
|
||||||
} else {
|
|
||||||
return [part];
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
const Post = ({ content, handlequoteclick, comment }) => {
|
|
||||||
const sanitizedContent = DOMPurify.sanitize(content);
|
const sanitizedContent = DOMPurify.sanitize(content);
|
||||||
|
|
||||||
return (
|
const lines = sanitizedContent.split(/(?:\r\n|\r|\n)/);
|
||||||
<ReactMarkdown
|
const greentextLines = lines.map((line, index) => {
|
||||||
children={sanitizedContent}
|
if (line.startsWith('>')) {
|
||||||
remarkPlugins={[blockquoteToGreentext]}
|
return <div className="greentext" key={`gt-${index}`}>{line}</div>;
|
||||||
components={{
|
} else if (line === '') {
|
||||||
img: () => null,
|
return <div key={`empty-${index}`}> </div>;
|
||||||
video: () => null,
|
}
|
||||||
source: () => null,
|
return <div key={`line-${index}`}>{line}</div>;
|
||||||
gif: () => null,
|
});
|
||||||
p: ({ children }) => (
|
|
||||||
<p>{createQuotelink(handlequoteclick, comment, children)}</p>
|
return <>{greentextLines}</>;
|
||||||
),
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Post;
|
export default Post;
|
||||||
Reference in New Issue
Block a user