fix greentext in rehype-sanitize

This commit is contained in:
Tom
2023-04-27 13:10:23 +02:00
parent 93bbbeddee
commit 1bd3fff25e
+13 -2
View File
@@ -1,10 +1,20 @@
import React from 'react'; import React from 'react';
import ReactMarkdown from 'react-markdown'; import ReactMarkdown from 'react-markdown';
// import { Link } from 'react-router-dom'; // import { Link } from 'react-router-dom';
import rehypeSanitize from 'rehype-sanitize'; import rehypeSanitize, { defaultSchema } from 'rehype-sanitize';
import breaks from 'remark-breaks'; import breaks from 'remark-breaks';
const customSchema = {
...defaultSchema,
tagNames: [...defaultSchema.tagNames, 'div'],
attributes: {
...defaultSchema.attributes,
div: ['className'],
},
};
const blockquoteToGreentext = () => (tree) => { const blockquoteToGreentext = () => (tree) => {
tree.children.forEach((node) => { tree.children.forEach((node) => {
if (node.type === 'blockquote') { if (node.type === 'blockquote') {
@@ -28,6 +38,7 @@ const blockquoteToGreentext = () => (tree) => {
}); });
}; };
// const createQuotelink = (handlequoteclick, comment, children) => { // const createQuotelink = (handlequoteclick, comment, children) => {
// const text = children.map((child) => (typeof child === 'string' ? child : child.props.children)).join(''); // 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 regex = /(\s|^)(c\/[A-Za-z0-9]{12}|c\/[A-Za-z0-9]{45})(?=\s|$)/g;
@@ -59,7 +70,7 @@ const Post = ({ content, handlequoteclick, comment }) => {
<ReactMarkdown <ReactMarkdown
children={doubleNewlineContent} children={doubleNewlineContent}
remarkPlugins={[blockquoteToGreentext, breaks]} remarkPlugins={[blockquoteToGreentext, breaks]}
rehypePlugins={[rehypeSanitize]} rehypePlugins={[[rehypeSanitize, customSchema]]}
components={{ components={{
img: () => null, img: () => null,
video: () => null, video: () => null,