如何在express.js jade模板中渲染markdown?
我使用express js框架。我有一个来自数据库的 markdownified 字符串,并希望在我的 jade 模板中将其呈现为 HTML。我安装了 node-markdown 并希望以这种方式呈现它:
app.js
var md = require("node-markdown").Markdown;
template.jade
- each note in todo.notes
div= md(note.string)
但是,它不会打印出任何内容......对此有什么建议吗?
谢谢!
编辑:自己解决了它,只是忘记将 md 变量放入我的视图中......
I use the express js framework. I have a markdownified string from the database and want to render it as HTML in my jade template. I installed node-markdown and want to render it this way:
app.js
var md = require("node-markdown").Markdown;
template.jade
- each note in todo.notes
div= md(note.string)
However, it doesn't print out anything... any advice at this?
Thanks!
EDIT: solved it myself, just forgot to get the md variable into my view...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
有一个“过滤器”的概念,它将“编译器”或“过滤器”访问者暴露给玉模板的一部分。
查看:https://github.com/visionmedia/jade
过滤器
:sass 必须安装 sass.js
:less 必须安装 less.js
:markdown 必须安装 markdown-js 安装或node-discount
:cdata
:coffeescript 必须安装coffee-script
您可以在模板中通过以下语法使用它:
http://jade-lang.com/reference/filters/
There is the concept of 'filters' that expose a 'compiler' or 'filter' visitor to a portion of the jade template.
Check out: https://github.com/visionmedia/jade
filters
:sass must have sass.js installed
:less must have less.js installed
:markdown must have markdown-js installed or node-discount
:cdata
:coffeescript must have coffee-script installed
You use it via this syntax in a template:
http://jade-lang.com/reference/filters/
我自己找到了解决方案:
问题是,我忘记将 md 变量传递到我的视图中。因此,要让 node-markdown 模块运行,您需要执行以下操作:
app.js header
app.js 路由 (传递 md 变量)
template .玉
I found the solution myself:
The problem was, I forgot to pass the md variable into my view. so what you have to do to get the node-markdown module running is the following:
app.js header
app.js route (passing the md variable)
template.jade
节点模块
node-markdown
已弃用。 标记为高级新版本。你可以这样尝试在你的路由器里面
你的玉模板里面
The node module
node-markdown
is deprecated. The marked is advanced new version. You can try like thisInside your router
Inside your jade template
如果您在 Jade 文件中使用 Marked,您可以执行如下简单操作:
If you're using Marked, in your Jade file, you can do something as simple as this:
你可以使用标记,然后你可以执行以下指令:
app.js
现在你可以调用每当您需要在模板玉上使用该功能时,例如您的情况:
template.jade
You can use marked, then you can do the following instructions:
app.js
Now you can call the function everytime you want it on template jade, example in your case:
template.jade