-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Comments
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 |
ah, the filters are actually compile-time to avoid wasting resources per request. you could expose a helper and just do |
Can't the filters receive the parent context? I'm trying to figure out a way to do this as well. |
filters are compile-time, most of them are things like coffeescript, markdown, stylus etc so compiling them per-request would be really wasteful |
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. |
you can just use functions, pass them as locals, or in express there are many ways to expose helper functions |
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 |
I used express-expose |
Much time has gone. Is still there no way to pass text variable to filter?
Or
I think in most cases it is necessary to pass text in variable. |
https://github.com/pugjs/jade/blob/master/docs/views/reference/filters.jade:
They are designed to not support dynamic content. |
This is strange. I don't see any difference. Filter the text from current jade file or take the text from the locals. |
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. |
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
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
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. |
I feel like this should work somehow. It doesn't even throw an error. |
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?
The text was updated successfully, but these errors were encountered: