问个问题 为什么node-markdown 转出来的内容会直接输出而不是变成html?
发布于 11 年前 作者 q1270989 4953 次浏览 最后一次编辑是 8 年前

http://198.100.114.49:8080/

地址如上.

div.content-perspective
	div.content
		div.content-inner
		     h3 
			a(href="/blog/#{blogc._id}")=blogc.title
			div.article=md(blogc.content)

jade模版. md 是传过来的

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

转完之后直接显示了 不是html <>都变成了

&lt;p&gt;&lt;code&gt;javascript
var this = o;
$(this).addClass('a');
&lt;/code&gt;&lt;/p&gt;

求指导.

5 回复

自己顶一下吧~

ReferenceError: /mydata/myweb/nodejs/views/blog-list.jade:27


current_user is not defined
    at eval (eval at <anonymous> (/mydata/myweb/nodejs/node_modules/jade/lib/jade.js:171:8), <anonymous>:126:6)
    at /mydata/myweb/nodejs/node_modules/jade/lib/jade.js:172:35
    at Object.exports.render (/mydata/myweb/nodejs/node_modules/jade/lib/jade.js:206:14)
    at View.exports.renderFile [as engine] (/mydata/myweb/nodejs/node_modules/jade/lib/jade.js:233:13)
    at View.render (/mydata/myweb/nodejs/node_modules/express/lib/view.js:75:8)
    at Function.app.render (/mydata/myweb/nodejs/node_modules/express/lib/application.js:501:10)
    at ServerResponse.res.render (/mydata/myweb/nodejs/node_modules/express/lib/response.js:755:7)
    at render (/mydata/myweb/nodejs/controllers/blog.js:37:9)
    at _all (/mydata/myweb/nodejs/node_modules/eventproxy/lib/eventproxy.js:230:16)
    at EventProxy.trigger (/mydata/myweb/nodejs/node_modules/eventproxy/lib/eventproxy.js:133:22)

应该是模板默认对输出的变量进行了转义(出于安全考虑,很多模板默认都这样) 具体神马原因,仔细看看文档就知道了。

(俺不懂Jade模板,表示很羡慕楼主)

@leizongmin 好了 sorry 调试代码忘记去掉了

so嘎 果然是呢 哈哈 非常感谢

div.article=md(blogc.content) 需要换成 div.article!=md(blogc.content)

回到顶部