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

No CSS with Gulp
gulp move files to parent directory
How to get gulp-jshint to ignore folders
Inserting specific file at index of a stream
How to pass array from gulp to other js files?
BrowserSync + Gulp with Vagrant not refreshing
gulp-tslint return undefined when required
Gulp watch only runs once
Gulp watch not working with imported files but works with main file
Gulp watch for css doesn't work
Using gulp for compiling of changed files only
How to run gulp task in visual studio code?
BrowserSync with custom URL
Multi-tenancy and Semantic UI
Display total number of errors with Gulp Jshint
Gulp watch entire folder & compile saved file

Categories

HOME
typo3
cors
openacc
cxf
snappy
popover
data-modeling
pdf-generation
markdown
vsixmanifest
ethereum
cakephp-2.0
swift3.1
vivado-hls
cucumberjs
django-rest-auth
uipath
gsuite
apdu
grunt-contrib-uglify
expressionengine
proof-general
drombler-fx
dynamic-memory-allocation
selenium3
mplab
slim-lang
voyager
campaign-monitor
multi-user
strategy-pattern
mybatis-generator
armadillo
server-side-swift
file-descriptor
electron-packager
superclass
mef
webmatrix
programming-pearls
reloaddata
grib
fileopendialog
stripes
mavlink
consolidation
eclipse-mars
joystick
xcode7.1
foreground
jira-agile
django-taggit
alchemy
musicbrainz
photogrammetry
log-analysis
teamwork
tinymce-plugins
chrome-mobile
mathics
frisby.js
breeze-sharp
parsefloat
nsmutableurlrequest
rails-migrations
webshim
adabas
lastinsertid
sygic
google-checkout
rbm
screensharing
idoc
teamsystem
motordriver
hypertable
django-admin-tools
umfpack
session-hijacking
noise-reduction
netbeans7.0
viewdata
virtual-destructor
carbon-emacs
hp-trim
user-preferences
scalable

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