Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

:markdown filter processing the text of a String variable #404

Closed
bobmonteverde opened this issue Nov 14, 2011 · 14 comments
Closed

:markdown filter processing the text of a String variable #404

bobmonteverde opened this issue Nov 14, 2011 · 14 comments

Comments

@bobmonteverde
Copy link

So I have a variable that's a sting containing markdown text (the body of an article for a simple node powered blog).

so, first I tried:

:markdown
  #{ article.body }

which outputs: <h1>{ article.body }</h1>

I also tried:

:markdown
  \#{ article.body}

which outputs the contents of article.body, BUT does not process the contents with the markdown filter.

So, is there a way to accomplish what I am trying?

@bobmonteverde
Copy link
Author

I ended up just using markdown.toHTML function, to process the markdown to html before sending to the template. I guess that works, though I think it would be nice to be able to do this just in the template

@tj
Copy link
Contributor

tj commented Nov 15, 2011

ah, the filters are actually compile-time to avoid wasting resources per request. you could expose a helper and just do p!= markdown(article.body)

@shinuza
Copy link

shinuza commented Nov 22, 2011

Can't the filters receive the parent context? I'm trying to figure out a way to do this as well.

@tj
Copy link
Contributor

tj commented Nov 22, 2011

filters are compile-time, most of them are things like coffeescript, markdown, stylus etc so compiling them per-request would be really wasteful

@shinuza
Copy link

shinuza commented Nov 22, 2011

OK, is there another way to extend Jade with features like what you can do in Django?

Edit: I'm trying to compile a set of basic features you would want to use in templates. I trying to find the simplest way for them to be available for template authors.

I'm guessing filters in Jade are not the same as filters in Django.

@tj
Copy link
Contributor

tj commented Nov 22, 2011

you can just use functions, pass them as locals, or in express there are many ways to expose helper functions

@tj
Copy link
Contributor

tj commented Jun 17, 2012

This issue has been inactive for over 1 month so I'm closing it. If you think it's still an issue re-open. - tjbot

@tj tj closed this as completed Jun 17, 2012
@jwerre
Copy link

jwerre commented Jun 18, 2012

I used express-expose

@Denis535
Copy link

Denis535 commented Jan 6, 2016

Much time has gone. Is still there no way to pass text variable to filter?
What's problem to do something the next?

:markdown-it(content=article.body)

Or

:markdown-it= article.body

I think in most cases it is necessary to pass text in variable.

@TimothyGu
Copy link
Member

https://github.com/pugjs/jade/blob/master/docs/views/reference/filters.jade:

Filters are rendered at compile time, which makes them fast but also means that they cannot support dynamic content or options.

They are designed to not support dynamic content.

@Denis535
Copy link

Denis535 commented Jan 7, 2016

This is strange. I don't see any difference. Filter the text from current jade file or take the text from the locals.

@ForbesLindesay
Copy link
Member

There are two stages to generating html from jade. The first step (compiling) happens once on application startup, and doesn't have access to local variables, only to the raw source code. The second stage (rendering) happens for every single page request. It's responsible for combining the compiled code with the locals. It's critical that this stage is really fast.

pcraig3 added a commit to cds-snc/cra-claim-tax-benefits that referenced this issue Jul 11, 2019
Since we're going to be (eventually) creating different user
journies through the application, asking someone clicking through
to enter a correct

- access code
- SIN
- date of birth

Is a pretty big lift, even though that's how the app works.

To make it easier, I updated the hint text so that it shows the
correct value for the current user.

This is just a "dev" feature, so we will revert to static hint text
once we have a live service.

Also notable, I was originally going to add a pug filter the way that
they are documented on the website, but pug filters proper can't
take any variables. They only work with static content.

> Filters are rendered at compile time. This makes them fast, but it also means that they cannot support dynamic content or options.

This means that we needed just a pure JS function instead to display
SIN numbers in a human readable way.

Sources:
- https://pugjs.org/language/filters.html#custom-filters
- pugjs/pug#404
pcraig3 added a commit to cds-snc/cra-claim-tax-benefits that referenced this issue Jul 11, 2019
Since we're going to be (eventually) creating different user
journies through the application, asking someone clicking through
to enter a correct

- access code
- SIN
- date of birth

Is a pretty big lift, even though that's how the app works.

To make it easier, I updated the hint text so that it shows the
correct value for the current user.

This is just a "dev" feature, so we will revert to static hint text
once we have a live service.

Also notable, I was originally going to add a pug filter the way that
they are documented on the website, but pug filters proper can't
take any variables. They only work with static content.

> Filters are rendered at compile time. This makes them fast, but it also means that they cannot support dynamic content or options.

This means that we needed just a pure JS function instead to display
SIN numbers in a human readable way.

Sources:
- https://pugjs.org/language/filters.html#custom-filters
- pugjs/pug#404
@ghost
Copy link

ghost commented Dec 20, 2019

I use pugjs to generate html files much like in statically generated websites. For this, it would be very useful to generate html from markdown using variables.

@buckle2000
Copy link

:markdown-it= article.body

I feel like this should work somehow.

It doesn't even throw an error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants