Markdown/HTML无法从Netlify CMS产生的前肌中正确解析。

发布于 2025-02-03 17:51:29 字数 689 浏览 4 评论 0原文

我一直陷入困境。我有两个输入未正确显示的输入,一个降价小部件和列表小部件。它们都显示为一个长字符串。我认为至少我需要为前者添加一个Markdown解析器,以便我以类似的方式使用Markdown-it:

https://github.com/11ty/eleventy/issues/236

它正在添加段落中断,但它们在页面上以p标签显示在页面上。我认为这是因为我已经在p标签之间嵌套了解析文本,但是如果我删除这些文本,则根本没有出现。当我查看高度创建的HTML文件时,标签显示为“& p& gt;” (没有空间),在尝试解释HTML时,浏览器似乎无法正确读取。我正在使用nunjucks进行模板。我的.eleventy.js文件当前看起来像这样。我想念什么?另外,Markdown过滤器似乎只想拿一个字符串,因此我不确定从列表开始。

I've been stuck on this for an embarrassingly long time. I have two inputs that aren't displaying correctly, a markdown widget and the list widget. They both appear as one long string. I thought I needed to add a markdown parser for the former at least so I'm using markdown-it in a manner similar to this:

https://github.com/11ty/eleventy/issues/236

It is adding paragraph breaks where they should be but they show up on the page as p tags. I thought this was because I already had the parsed text nested between p tags but if I delete those nothing shows up at all. When I look at the html file created by eleventy, the tags show up as "< ;p> ;" (without the spaces) which it seems the browser isn't reading correctly when trying to interpret the html. I'm using nunjucks for templating if that matters. My .eleventy.js file looks like this currently. What am I missing? Also the markdown filter seems to only want to take a string so I'm not sure where to even begin with the list.

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无可置疑 2025-02-10 17:51:29

默认情况下,输出模板时,nunjucks html-escapes所有变量。除非您试图渲染HTML输入,否则这就是您大多数时候想要的。

您可能需要尝试使用 safe filter 在您的Markdownify过滤器之后。

{{ markdownContent | markdownify | safe }}

By default, Nunjucks HTML-escapes all variables when outputting templates. This is what you want most of the time, unless you're trying to render HTML input.

You might want to try using the safe filter after your markdownify filter.

{{ markdownContent | markdownify | safe }}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文