首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >一饮而尽,将渲染器和目的地分开。

一饮而尽,将渲染器和目的地分开。
EN

Stack Overflow用户
提问于 2015-10-04 08:23:50
回答 1查看 85关注 0票数 0

我试图获取一个输入标记文件,通过两个不同的呈现器运行它,并将输出保存到不同的文件夹中。我的计划是使用区块引号来防止特定内容在其中一个输出中呈现。这是我的吞咽文件:

代码语言:javascript
复制
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);

});

运行此操作时不会出现错误,但这两个内容都是相同的,并且附加的p标记被包装在标题周围。如果我将其中一个注释掉,然后返回另一个,它就能正常工作。

我做错了什么?

输入文件:

代码语言:javascript
复制
## This is a heading

> This is mlive only stuff

Here's some other stuff for both.

> one more for mlive

和输出(两者相同)

代码语言:javascript
复制
<p><h2 id="this-is-a-heading">This is a heading</h2></p>
<p>This is mlive only stuff</p>
<p>Here&#39;s some other stuff for both.</p>
<p>one more for mlive</p>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-10-04 19:38:47

经过更多的挖掘,我无意中发现了gulp-mirror,并设法做到了这一点。使用它,我能够将目标调用移动到延迟类型,然后将源映射到它们。下面是新的gulpfile (通过额外的调整从标题中删除ids )

代码语言:javascript
复制
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()
        ));
});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32931486

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档