我正在尝试从firebase数据库中提取markdown字符串,然后使用react-markdown将其呈现为组件。但是标记字符串不能正确显示。我认为问题是从新的线路开始的。
我试着声明了我放在其中的变量。它起作用了。markdown string which is created in Component
而是从firebase数据库中拉出的标记字符串。它不能正确显示。markdown string which is pulled from firebase database
以下是我的代码
export default function BlogTemplate() {
const { id } = useParams();
useFirestoreConnect([
{
collection: "communications",
doc: id
}
]);
const post = useSelector(
state =>
state.firestore.data.communications &&
state.firestore.data.communications[id]
);
if (post) {
const input =
"# This is a header\n\nAnd this is a paragraph \n\n # This is header again"; // this is a markdown string created in Component
const postContent = post.content; // This is the markdown string pulled from firebase database
return (
<Layout>
<Container>
<Content className="pt-5 pb-5">
<ReactMarkdown source={input} />
<ReactMarkdown source={postContent} />
</Content>
</Container>
</Layout>
);
} else {
return <p>Loading...</p>;
}
}发布于 2021-01-07 03:10:00
看起来你需要在之前添加两个空格,\n就像这样:“这是一个标题\n \n这是一个段落”。
如果这对你有效,请让我知道。
更多信息请点击此处:https://github.com/remarkjs/react-markdown/issues/273
https://stackoverflow.com/questions/60332183
复制相似问题