React-Markdown Next.js 13 无法正确渲染 markdown,rehypePlugins 元素也被忽略

问题描述 投票:0回答:1

我正在尝试使用react-markdown和rehypeRaw在Next.js 13构建的我的博客上实现markdown,以允许其中包含HTML。我在此文件中使用“使用客户端”。 但是,我的文本仅在我使用 markdown(#、## 等)时才显示,并且标题级别被忽略,它始终是相同的小尺寸。澄清一下,像strong这样的明星造型是可行的。当我尝试像这样使用 rehypeRaw 时:

<ReactMarkdown
        // @ts-expect-error
        rehypePlugins={[rehypeRaw]}
      >
    <h1> yessss</h1>
</ReactMarkdown>

html 树中没有显示任何内容,我在线收到此错误:

Type 'Element' is not assignable to type 'string'.

我只是希望能够在我的 Markdown 内容中使用 HTML 和 tailwindCSS。或者因为这只是只有我可以发布的内容,我应该使用angerlySetInnerHTML吗?我知道至少该解决方案在我测试时可以与 Tailwind 配合使用。即使我是唯一有权访问该网站的人,这会是一个漏洞吗?

// @ts expect error 
是许多 GitHub 问题所描述的 rehypePlugins 抛出此错误的解决方法:

Type '(options?: Options | null | undefined) => (tree: Root, file: VFile) => Root' is not assignable to type 'Pluggable<any[]>'.
  Type '(options?: Options | null | undefined) => (tree: Root, file: VFile) => Root' is not assignable to type 'Plugin<any[], any, any>'.
    Type '(tree: Root, file: VFile) => Root' is not assignable to type 'void | Transformer<any, any>'.
      Type '(tree: Root, file: VFile) => Root' is not assignable to type 'Transformer<any, any>'.

我还遵循了此处接受的答案,以便能够正确呈现常规降价: react-markdown 不渲染 Markdown

reactjs next.js markdown next.js13 react-markdown
1个回答
0
投票

我在这里回答了一个熟悉的问题https://stackoverflow.com/a/77762348/7262646

<ReactMarkdown
        // @ts-expect-error
        rehypePlugins={[rehypeRaw] as any}
      >
    <h1> yessss</h1>
</ReactMarkdown>
© www.soinside.com 2019 - 2024. All rights reserved.