【问题标题】:Adding multiple line break in react-markdown在 react-markdown 中添加多个换行符
【发布时间】:2021-10-31 16:58:37
【问题描述】:

目前我正在使用 React,并且我在strapi CMS 中的富文本中的内容在我的降价版本中以我想要的方式隔开,但是一旦我切换到预览,或在我的浏览器中查看内容,空间消失。我已经尝试添加<br/>标签,但仍然没有换行。

这是我的strapi markdown中的内容:

但这是我网页上的输出:

这是我当前的代码:

import ReactMarkdown from "react-markdown";
import rehypeRaw from "rehype-raw";
export default function name({ posts }) {
  return (
    <>
        <div>
          {posts.Title}
        </div>
      <div>
        <ReactMarkdown children={posts.Content} rehypePlugins={[rehypeRaw]} />
      </div>
    </>
  );
}

【问题讨论】:

标签: reactjs strapi react-markdown


【解决方案1】:

要添加多个换行符,应该这样做:

import React from "react";
import "./styles.css";

import ReactMarkdown from "react-markdown";

export default function App() {
  const markdown = `hello
  \n &nbsp;
  \n &nbsp;
  \n &nbsp;
  \n &nbsp;
  \n
  world
  `;

  return (
    <div className="App">
      <ReactMarkdown source={markdown} />
    </div>
  );
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-07-03
    • 1970-01-01
    • 1970-01-01
    • 2021-08-09
    • 2011-08-20
    • 2013-02-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多