将Markdown原始文本传递给Jade [英] Passing raw Markdown text to Jade

查看:114
本文介绍了将Markdown原始文本传递给Jade的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在玩我的第一个Node.js Express 应用程序,并且每个程序员都知道,第一件事在测试新框架时,您应该构建博客!无论如何,我想在Markdown中编写文章,然后在视图中进行渲染.我看到Jade允许使用过滤器在视图内部完成此操作,但是我无法正常工作.

I'm playing around with my first Node.js Express application, and as every programmer knows, the first thing you should build when testing out a new framework is a blog! Anyway, I'd like to write the articles in Markdown and then render it in the view. I saw that Jade allows for this to be done inside the view itself, using filters, but I can't get that working.

为简化这种情况,这是我正在谈论的示例.

To simplify the situation, here's an example of what I'm talking about.

//app.js
res.render("article", {
    md : "Hello World!\n\n*Woo*"
});

//article.jade
section
    :markdown
        #{md}

但是,它输出以下内容:<section><h1>{md}</h1></section> ...它并不能替代我传递给它的变量.

But, that outputs this: <section><h1>{md}</h1></section>... it isn't substituting in the variables I've passed to it.

然后我尝试了这个:

//article.jade
section
    :markdown
        !{md}

输出为:

<section><p>Hello World!

*Woo*</p></section>

所以,现在它没有解析降价!

So, now it's not parsing the markdown!

我已经能够通过解析app.js文件中的markdown然后将HTML传递到视图中进行显示来使其工作,但是我不知道,这看起来有点麻烦.

I have been able to get this to work by parsing the markdown in the app.js file and then passing the HTML to the view to display, but I dunno, that seems a bit messier.

是否可以将变量传递到Jade过滤器中?

Is there a way to pass variables into Jade filters?

推荐答案

您可以使用从节点传递到玉器中的函数来做到这一点:

You can do this with a function passed in to jade from node:

var md = require("node-markdown").Markdown;

然后将其作为本地传递到视图中

Then pass it into the view as a local:

res.render('view', { md:md, markdownContent:data });

然后通过调用函数在玉视图中渲染它:

Then render it in the jade view by calling the function:

!= md(markdownContent)

这篇关于将Markdown原始文本传递给Jade的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆