javascript - 想在 react-markdown 文件中编写脚本,但所有字符都已转义
问题描述
我在使用 Next 和 react-markdown 的降价网站上遇到问题。我想添加一些脚本,例如 Github gist 的嵌入标签,但所有字符都已转义。有没有解决脚本标签内的字符转义的方法?
我添加rehypePlugins={[rehypeRaw]}
到启用的 HTML 中:
// pages/post/[id].tsx
...
<ReactMarkdown components={components} rehypePlugins={[rehypeRaw]}>
{markdownBody}
</ReactMarkdown>
...
我试过了:
// posts/somemarkdwon.md
## H1 title here
normal text here
<p>hi<br />hi</span></p>
<script>const hi = "3"; alert(hi);</script>
输出:
<h2>H1 title here</h2>
<p>normal text here</p>
<p>hi<br/>hi</p>
<script>const hi = "3"; alert(hi);</script>
“3”转换为"3"
,脚本出错。
有没有人有好的解决方案?
解决方案
推荐阅读
- c# - 如何使用 AlarmManager 在 Xamarin 中设置警报
- python - 操作超时,python,CVE-2009-2629
- python - Pandas 从数据集中获取 MySQL 创建表可执行脚本
- arrays - 如何使用欧几里得距离访问最相似行上的特定项目?
- sql-server - 导出 SSMS 查询结果时,将遇到的每个空格字符替换为逗号?
- c# - 从 C# 插入 QODBC
- google-apps-script - 如何修复 Google 表格 RTL?
- php - 在 MySQL 中将 unix 时间戳转换为以毫秒为单位的日期时间
- c# - Crystal Reports 无法在 IIS 10 和 Windows Server 2019 上运行
- r - 使用 AnomalyDetectionTs 包在 R 中进行时间序列异常检测