Jade: Pass markdown filter a variable.

2,490 views
Skip to first unread message

Geert Pasteels

unread,
Feb 5, 2012, 10:56:37 AM2/5/12
to expre...@googlegroups.com
How can I pass a variable to the markdown filter?

I tried

:markdown
  #{description}

:markdown=description

But none seem to be working.

vision media [ Tj Holowaychuk ]

unread,
Feb 5, 2012, 11:11:38 AM2/5/12
to expre...@googlegroups.com
filters are compile-time, they can't have access to vars since they're only compiled once


--
You received this message because you are subscribed to the Google Groups "Express" group.
To view this discussion on the web visit https://groups.google.com/d/msg/express-js/-/vLk59_3x9NkJ.
To post to this group, send email to expre...@googlegroups.com.
To unsubscribe from this group, send email to express-js+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/express-js?hl=en.



--
Tj Holowaychuk
Vision Media
President & Creative Lead

Alfred Nerstu

unread,
Mar 4, 2012, 8:31:19 AM3/4/12
to expre...@googlegroups.com
Were just trying the same thing.

What are your suggested approach to this?

I've got the markdown-js package

Thanks!


On Sunday, February 5, 2012 5:11:38 PM UTC+1, vision media [ Tj Holowaychuk ] wrote:
filters are compile-time, they can't have access to vars since they're only compiled once

On Sun, Feb 5, 2012 at 7:56 AM, Geert Pasteels wrote:
How can I pass a variable to the markdown filter?

I tried

:markdown
  #{description}

:markdown=description

But none seem to be working.

--
You received this message because you are subscribed to the Google Groups "Express" group.
To view this discussion on the web visit https://groups.google.com/d/msg/express-js/-/vLk59_3x9NkJ.
To post to this group, send email to expre...@googlegroups.com.
To unsubscribe from this group, send email to express-js+unsubscribe@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/express-js?hl=en.

Brandon Martin

unread,
Mar 4, 2012, 8:48:21 AM3/4/12
to expre...@googlegroups.com
I had a similar issue before. I used github-flavored-markdown and parsed the markdown before handing off to the view. ie:

ghm = require("github-flavored-markdown");

exports.mission = function(req, res) {
  Content.findOne({}, function(err, content) {
    content.body = ghm.parse(content.body);
    res.render('about/index', {
      content: content,
    });
  });
};

Then in index.jade

 

--
Brandon Martin
Lead Developer



To view this discussion on the web visit https://groups.google.com/d/msg/express-js/-/lPgiuGq4Dh0J.

To post to this group, send email to expre...@googlegroups.com.
To unsubscribe from this group, send email to express-js+...@googlegroups.com.

Brandon Martin

unread,
Mar 4, 2012, 8:50:11 AM3/4/12
to expre...@googlegroups.com
Sorry hit send by accident. Then in the view just did

div !{mission.body}

--
Brandon Martin
Lead Developer



Brandon Martin

unread,
Mar 4, 2012, 9:00:53 AM3/4/12
to expre...@googlegroups.com
Sorry I was trying to make it more generic then what I am doing and had some typos. Let's try this again:

ghm = require("github-flavored-markdown");

exports.about = function(req, res) {
  Content.findOne({}, function(err, content) {
    content.body = ghm.parse(content.body);
    res.render('about/index', {
      content: content,
    });
  });
};

Then in about/index.jade

div !{content.body}

--
Brandon Martin
Lead Developer



Paul Vencill

unread,
Mar 4, 2012, 9:19:29 AM3/4/12
to expre...@googlegroups.com
That's the only solution I was able to find, too, though in my case I made it a view helper and called it from the view:

app.helpers({ md : function(text){
   return ghm.parse(text);
}});

div != md(content.body)

Sean MacAvaney

unread,
Jan 4, 2015, 5:53:14 PM1/4/15
to expre...@googlegroups.com
FYI: `github-flavored-markdown` is now deprecated. Use `marked` instead.

https://github.com/chjj/marked
To unsubscribe from this group, send email to express-js+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/express-js?hl=en.



--
Tj Holowaychuk
Vision Media
President & Creative Lead

--
You received this message because you are subscribed to the Google Groups "Express" group.
To view this discussion on the web visit https://groups.google.com/d/msg/express-js/-/lPgiuGq4Dh0J.
To post to this group, send email to expre...@googlegroups.com.
To unsubscribe from this group, send email to express-js+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/express-js?hl=en.

Samir Seetal

unread,
Feb 16, 2015, 5:35:44 AM2/16/15
to expre...@googlegroups.com
Hey guys,

With the new marked library, you can use the JavaScript to render.

    script(src="/js/marked.min.js") // https://github.com/chjj/marked/blob/master/marked.min.js
    script.
        $("#appdescription").html(marked('#Hello'));

Samir
Reply all
Reply to author
Forward
0 new messages