jade filter :markdown for an object with a

扶醉桌前 提交于 2019-12-02 02:45:50

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:

Shaurabh Bharti

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.

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