From bb7452e63411cd55aa8d5e9afbb78d28eb685ef5 Mon Sep 17 00:00:00 2001 From: Christer Eckermann Date: Sun, 27 Aug 2017 21:17:53 +0100 Subject: [PATCH 1/2] Made it possible to customise the split string regex. --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index d6abb9a..9007a1a 100644 --- a/index.js +++ b/index.js @@ -9,6 +9,7 @@ function split(opts) { var self = this; var options = opts || {}; var stop = options.stop || 'stop'; + var splitStr = options.splitStr || /\s*\s*/g; return through.obj(function (file, enc, cb) { if (file.isNull()) { return cb(null, file); @@ -23,9 +24,8 @@ function split(opts) { var contents = file.contents.toString(enc); // detect split comments and build a list of splits - var regex = /\s*\s*/g; var result, splits = []; - while (result = regex.exec(contents)) { + while (result = splitStr.exec(contents)) { splits.push({ name: result[1], start: result.index + result[0].length }); if (splits.length > 1) { splits[splits.length - 2].end = result.index; From 704756b2d35ee6314196ae2da64e32ff4594cc13 Mon Sep 17 00:00:00 2001 From: Christer Eckermann Date: Sun, 27 Aug 2017 21:39:27 +0100 Subject: [PATCH 2/2] Updated explaining the new splitStr option. --- README.md | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 6d459f9..a229dc0 100644 --- a/README.md +++ b/README.md @@ -37,11 +37,27 @@ gulp.task('foo', function() { ### HTML file -The plugin will look for comments of the form: +By default plugin will look for lines in the HTML like this: -`` +`` -Everything following one of these comments will be piped to a file named `filename.ext`, +This divider be customised by setting the `splitStr` option to a valid regex value, +where group 1 represents the desired filename. By default the following regex is used: + +```js +var htmlsplit = require('gulp-htmlsplit'); + +gulp.task('foo', function() { + gulp.src('./*.html') + .pipe(htmlsplit( + // Where (\S+) represents the group with the file name + splitStr: /\s*\s*/g + )) + .pipe(gulp.dest('build')); +}) +``` + +Everything following one of these dividers will be piped to a file named `myFilename.ext`, until another `split` comment is encountered, or the file ends. If the HTML file does not begin with a `split` comment, the contents will be discarded