Git Product home page Git Product logo

Comments (8)

Renovamen avatar Renovamen commented on July 27, 2024 1
+ import rehypeRaw from "rehype-raw";

<ReactMarkdown 
   children={this.state.storeMd[this.props.id]} 
   linkTarget="_blank" 
   remarkPlugins={[gfm]} 
+  rehypePlugins={[rehypeRaw]}
   components={Highlighter(this.props.dark as boolean)} 
 />

如果是 typescript 报错的话,用我最新的代码试试?我刚升级了一下依赖。

from playground-macos.

Renovamen avatar Renovamen commented on July 27, 2024

我用了 react-markdown 来渲染 Markdown,它默认会忽视掉 Markdown 里的 HTML(为了安全性)。但如果想支持 HTML 语法的话,参考它的文档装一个插件 rehype-raw 和修改下面这段代码就可以了:

<ReactMarkdown
children={this.state.storeMd[this.props.id]}
linkTarget="_blank"
remarkPlugins={[gfm]}
components={Highlighter(this.props.dark as boolean)}
/>

因为我目前没有这个需求,同时考虑到打包大小,我暂时应该不会装这个插件,非常感谢。

from playground-macos.

IILee5 avatar IILee5 commented on July 27, 2024

我昨天尝试在react-markdown中加入rehype-raw插件,但是渲染失败了,可能是方式不太对。我会去尝试解决它,感谢您的回复😄️那我把这个issues关了,自己研究一下加进去

from playground-macos.

Renovamen avatar Renovamen commented on July 27, 2024

我刚试了一下是可以的 😂,有什么报错吗?

from playground-macos.

IILee5 avatar IILee5 commented on July 27, 2024

😄️可以把相关代码帖一下吗大佬,我react不是特别熟悉,可能也是代码写错了哈哈

from playground-macos.

IILee5 avatar IILee5 commented on July 27, 2024

image
生效了!果然是我代码写错了。
大佬是这样的

remarkPlugins={[gfm]} 
rehypePlugins={[rehypeRaw]}

而我自己一开始是这样子的

remarkPlugins={[gfm,rehypeRaw]}

我以为这里是个数组,受教了哈哈

from playground-macos.

Renovamen avatar Renovamen commented on July 27, 2024

我以为这里是个数组,受教了哈哈

这的确是个数组,但这俩 props 不一样啊,一个是 remarkPlugins 一个是 rehypePlugins,所以得分开传 😂

from playground-macos.

IILee5 avatar IILee5 commented on July 27, 2024

这的确是个数组,但这俩 props 不一样啊,一个是 remarkPlugins 一个是 rehypePlugins,所以得分开传 😂

感谢大佬哈哈,这模板真的太炫酷了👍,情不自禁的加了很多乱七八糟的东西上去

from playground-macos.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.