2023-03-29 13:37:36 +02:00
|
|
|
import React from 'react';
|
|
|
|
|
import DOMPurify from 'dompurify';
|
|
|
|
|
|
2023-04-21 16:18:36 +02:00
|
|
|
const Post = ({ content }) => {
|
2023-03-29 13:37:36 +02:00
|
|
|
const sanitizedContent = DOMPurify.sanitize(content);
|
|
|
|
|
|
2023-04-21 16:18:36 +02:00
|
|
|
const lines = sanitizedContent.split(/(?:\r\n|\r|\n)/);
|
|
|
|
|
const greentextLines = lines.map((line, index) => {
|
|
|
|
|
if (line.startsWith('>')) {
|
|
|
|
|
return <div className="greentext" key={`gt-${index}`}>{line}</div>;
|
|
|
|
|
} else if (line === '') {
|
|
|
|
|
return <div key={`empty-${index}`}> </div>;
|
|
|
|
|
}
|
|
|
|
|
return <div key={`line-${index}`}>{line}</div>;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return <>{greentextLines}</>;
|
2023-03-29 13:37:36 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default Post;
|