I know there's already been a bit of discussion on this question (see this Google Group thread). Jade filters don't pre-compile... they're compile-time only.
But I'm using Jade with Gulp (using Gulp-Jade plugin) for static building (ie: I'm not using Express).
How does one filter Markdown from data without using Express, from within Gulp?
Or, another way to phrase the question that might be quicker for folks to understand, how do I apply this Stack Overflow answer, or this one, within a Gulp task?
For example, I have this gulpfile:
gulpfile.js
gulp.task('jade' function() {
return gulp.src('./source.jad')
.pipe(jade({
pretty: true,
locals: jsyaml.load(fs.readFileSync('./data.yaml', 'utf8'))
}))
.pipe(gulp.dest('./build/'));
});
Markdown filter I need to somehow add to locals
({ md : function(text){
return markdown.parse(text);
}});
And a Yaml Data file
- description: >
This is a description **that would greatly benefit from Markdown**.
There are many seemingly promising answers in this Stack Overflow question (especially this one), but I can't figure out how to use their syntax with Gulp (without res.render
).
I've tried this in my gulpfile:
// require markdown engine
var markdown = ('markdown-js');
// jade task
gulp.task('jade' function() {
return gulp.src('./source.jad')
.pipe(jade({
pretty: true,
locals: jsyaml.load(fs.readFileSync('./data.yaml', 'utf8')),
md: markdown // added this... doesn't work
}))
.pipe(gulp.dest('./build/'));
});
Grateful for any insight folks might have.