jade filter :markdown for an object with a

自闭症网瘾萝莉.ら 提交于 2019-12-20 03:28:14

问题


I have an object from the database with some markdown markup I would like to render with jade. But how? When I apply the :markdown filter I can't use the object as object anymore, but it get's treated as text.

I started here:

p
   :markdown
      entry.content

Which renders to plain:

entry.content

So I tried putting = and - in front or wrapping #{} arround it. Is it possible at all?


回答1:


Filters are compile-time, so if you want to run a markdown filter on a run-time variable, you'll have to render the markdown yourself and pass it to your jade view:

  • https://groups.google.com/forum/?fromgroups=#!topic/express-js/8H4HNcoeekk



回答2:


I found a simple way of doing this, as explained in this answer. It uses marked library so first install it.

$ npm install marked --save

In router page

var markdown = require('marked');
var text = '**new text**';
res.render('template', {text:text, markdown:markdown});

In template.jade, try any of following lines

!= markdown(text);
p!= markdown(text);

This is cleanest way of implementing dynamic filters for markdown, in my opinion.



来源:https://stackoverflow.com/questions/14129272/jade-filter-markdown-for-an-object-with-a

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!