by-paragraph.js (569B)
1 const through = require('through2'); 2 const multipipe = require('multipipe'); 3 const line_for_line = require('./line-for-line'); 4 5 module.exports = () => 6 multipipe( 7 line_for_line(), 8 through.obj(function(line, enc, cb) { 9 line = line.toString(); 10 this.buffer = this.buffer || []; 11 12 // Emit paragraph on empty line 13 if (!line.length) { 14 if (this.buffer.length) { 15 this.push(this.buffer.join('\n')); 16 } 17 this.buffer = []; 18 return cb(); 19 } 20 21 this.buffer.push(line); 22 cb(); 23 }) 24 )