reactjs - 在 NextJS/React 中渲染 markdown 的问题
问题描述
我再次尝试在 NextJS/React 中呈现 markdown。由于某种原因,我的代码不起作用,这里是:
import ReactMarkdown from "react-markdown";
import gfm from 'remark-gfm';
const PostContent = () => {
const source = `
# Hello, world!
---
~this doesn't work.~
`
return (
<ReactMarkdown remarkPlugins={[gfm]} children={source} />
);
};
export default PostContent;
它不是渲染降价,而是正常输出文本,就好像它是 JSON:
谁能告诉我为什么会发生这种情况以及如何解决?谢谢!
我无法提供更多细节,因为这就是所有代码。
解决方案
这似乎是一个空白问题,你太多了。
这不起作用:
const PostContent = () => {
const source = `
# Hello, world!
---
~this doesn't work.~
`
return (
<ReactMarkdown remarkPlugins={[gfm]} children={source} />
);
};
这有效:
const PostContent = () => {
const source = `
# Hello, world!
---
~this doesn't work.~
`;
return <ReactMarkdown remarkPlugins={[gfm]} children={source} />;
};
请注意,每行的“前导”空格已被删除
推荐阅读
- signalr - 如何在 Blazor 服务器端更新多个用户?
- sql - 具有 auto_increment 的两列
- php - 有没有办法在不使用 Imagick 和其他库的情况下检查 .gif 图像是否透明?
- bash - 按名称递归查找所有文件,使用shell脚本解密并重命名它们
- regex - $regex 查找整个单词,mongodb
- angular - 如何为Angular 8找到具有特定值的对象数量
- php - php 处理 & 作为 URL 中字符串的一部分
- wordpress - Apple Pay with Stripe - Wordpress 安装验证 - GCP
- javascript - 将 Javascript 文件与 wordpress 插件链接
- python - 在 python/kivy 中使用 screenmananger 时出现黑屏