首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >带有react-markdown的新行

带有react-markdown的新行
EN

Stack Overflow用户
提问于 2020-02-21 12:21:49
回答 1查看 2.9K关注 0票数 1

我正在尝试从firebase数据库中提取markdown字符串,然后使用react-markdown将其呈现为组件。但是标记字符串不能正确显示。我认为问题是从新的线路开始的。

我试着声明了我放在其中的变量。它起作用了。markdown string which is created in Component

而是从firebase数据库中拉出的标记字符串。它不能正确显示。markdown string which is pulled from firebase database

以下是我的代码

代码语言:javascript
复制
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>;
  }
}
EN

回答 1

Stack Overflow用户

发布于 2021-01-07 03:10:00

看起来你需要在之前添加两个空格,\n就像这样:“这是一个标题\n \n这是一个段落”。

如果这对你有效,请让我知道。

更多信息请点击此处:https://github.com/remarkjs/react-markdown/issues/273

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60332183

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档