How to Convert Markdown to HTML with Gulp

03. March 2017 Note , ,

Following is an example which converts markdown to custom tag for Riot.js.

const marked      = require( 'gulp-marked' )
const replace     = require( 'gulp-replace' )
const rename      = require( 'gulp-rename' )

gulp.task( 'md', () => {
  gulp.src( 'README.md' )
    .pipe( marked( {} ) )
    // eslint-disable-next-line quotes
    .pipe( replace( /^/, '<home-contents class="home-contents">' + "\n" + '<div class="wrap">' ) )
    // eslint-disable-next-line quotes
    .pipe( replace( /$/, '</div>' + "\n" + '</home-contents>' ) )
    .pipe( replace( /<table>/, '<table class="table table-bordered">' ) )
    .pipe( rename( ( path ) => {
      path.basename = 'home-contents'
      path.extname = '.tag'
    } ) )
    .pipe( gulp.dest( 'tags' ) )
} )

 


Leave a Reply

Your email address will not be published. Required fields are marked *