gulp


gulp markdown to separate renderers and destinations


I'm attempting to take an input markdown file, run it through 2 different renderers, and save the output to different folders. My plan is to use blockquotes to keep specific content from rendering in one of the outputs. Here's my gulp file:
var gulp = require('gulp'),
marked = require('marked'),
markdown = require('gulp-markdown'),
cache = require('gulp-cached'),
lazypipe = require('lazypipe'),
merge = require('merge-stream');
gulp.task('markdown', function () {
// setup mlive
var mlive_renderer = new marked.Renderer();
mlive_renderer.blockquote = function (quote) {
return quote;
};
var mliveTasks = lazypipe()
.pipe(markdown, {
renderer: mlive_renderer
});
// setup hudsonvilleathletics
var hudsonvilleathleics_renderer = new marked.Renderer();
hudsonvilleathleics_renderer.blockquote = function(){ return ''; };
var hudsonvilleathleticsTasks = lazypipe()
.pipe(markdown, {
renderer: hudsonvilleathleics_renderer
});
// create out pipe of src content
var sources = gulp.src('src/**/*.md')
.pipe(cache('markdown'));
var mlive = sources
.pipe(mliveTasks())
.pipe(gulp.dest('mlive'));
var hudsonvilleathletics = sources
.pipe(hudsonvilleathleticsTasks())
.pipe(gulp.dest('hudsonvilleathletics'));
return merge(mlive, hudsonvilleathletics);
});
Running this completes without errors, but both contents are identical, and have additional p tags wrapped around headings. If I comment out one and just return the other it works fine.
What am I doing wrong?
input file:
## This is a heading
> This is mlive only stuff
Here's some other stuff for both.
> one more for mlive
and the output (identical for both)
<p><h2 id="this-is-a-heading">This is a heading</h2></p>
<p>This is mlive only stuff</p>
<p>Here's some other stuff for both.</p>
<p>one more for mlive</p>
After a lot more digging I stumbled upon gulp-mirror and have managed to get this working. Using that I was able to move the destination calls to the lazypipes, and then mirror the sources to them. Here's the new gulpfile (with an additional tweak to remove ids from headings)
var gulp = require('gulp'),
marked = require('marked'),
markdown = require('gulp-markdown'),
cache = require('gulp-cached'),
lazypipe = require('lazypipe'),
mirror = require('gulp-mirror');
gulp.task('markdown', function () {
// start of by removing the id's for headings
var heading = function (text, level) {
return '<h' + level + '>' + text + '</h' + level + '>\n';
};
/*
* mLive Setup
*
* convert any block quotes back to regular old p tags and save in the mlive folder
*/
var mliveRenderer = new marked.Renderer();
mliveRenderer.heading = heading;
mliveRenderer.blockquote = function(quote){
return quote;
};
var mliveTasks = lazypipe()
.pipe(markdown, {
renderer: mliveRenderer
})
.pipe(gulp.dest, 'mlive/');
/*
* HudsonvilleAthletics Setup
*
* completely remove anything in block quotes and save to the other folder
*/
var hudsonvilleathleticsRenderer = new marked.Renderer();
hudsonvilleathleticsRenderer.heading = heading;
hudsonvilleathleticsRenderer.blockquote = function(){
return '';
};
var hudsonvilleathleticsTasks = lazypipe()
.pipe(markdown, {
renderer: hudsonvilleathleticsRenderer
})
.pipe(gulp.dest, 'hudsonvilleathletics/');
/*
* Finally run everything
*/
return sources = gulp.src('src/**/*.md')
.pipe(cache('markdown'))
.pipe(mirror(
mliveTasks(),
hudsonvilleathleticsTasks()
));
});

Related Links

Gulp-kss issues
Browserify - accurate build log in terminal with o: --colors, silimar to webpack
Minimist not finding arguments
Gulp.js. Same task on watch, with different parallel tasks
Split css for different devices
Gulpfile not working when module.exports references a Gulp task not a function?
Use gulp to process bowser files
Getting an error when trying to serve the app using browser-sync
Can't Sprite using gulp.spritesmith
How can I make build variables available to all JS files in gulp?
Gulp not installed globally?
gulp-useref deep folders error
use gulp+browserify+reactify, can't emit exit when got a ReactifyError
gulp-browserstack and gulp-cucumber don't seem to play nicely together
Gulp - Babel - EcmaScript-6 - Redux / Unhandled stream error in pipe
Delete all files using gulp except once that match pattern

Categories

HOME
internet-explorer
google-cloud-pubsub
itunesconnect
alasql
postsharp
x86-64
boxplot
hex
watson-iot
x509certificate
redhawksdr
pip
obd-ii
software-collections
google-my-business-api
google-search-appliance
vichuploaderbundle
expo
comma
appsettings
custom-component
lotusscript
email-client
rvm
my.cnf
pixels
nsopenpanel
adobe-captivate
utc
formtastic
csproj
undo
log4net-configuration
qt-designer
circle
gitosis
irr
superclass
encoder
infovis
rivets.js
stanford-nlp-server
noise
perldoc
liferay-ide
trusted-computing
scanf
glade
konakart
deck.js
django-celery
mrunit
aws-kms
jmap
ooad
fadein
controlpanel
event-tracking
play-json
php-gd
playn
euro
data-representation
tidesdk
gcc-warning
minko
crtdbg.h
fedena
apache-pivot
worklight-appcenter
serializer
class-library
nomachine
complete
kendo-window
objectdatasource
forward-declaration
friendly-url
cocotron
mysql2
ftpwebrequest
gssapi
dancer
django-1.4
reflexil
jmesa
pinchzoom
inserthtml
cgaffinetransform
capitalization
peoplepicker
hwnd
cinder
oaw
djangoappengine
projectgen
wtsapi32

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App