gulp-html-rebuild
v0.0.4
Published
Rebuild html with htmlparser2.
Downloads
3
Readme
gulp-html-rebuild
Run minodisk/htmlparser2#stack-storage and rebuild html.
Parse and rebuild html to observe coding conventions, and so on.
Install
$ npm install --save-dev gulp-html-rebuild
Usage
var gulp = require('gulp');
var rebuild = require('gulp-html-rebuild');
gulp.task('default', function () {
return gulp.src('index.html')
.pipe(rebuild({
onopentag: function (name, attrs) {
var classes = attrs.class.split(/\s+/);
var index;
if ((index = classes.indexOf('article')) === -1) {
return;
}
classes.splice(index, 1);
attrs.class = classes.join(' ');
return "<" + name + rebuild.createAttrStr(attrs) + ">";
}
}));
});
API
rebuild(options)
Gulp plugin for rebuilding html.
- Params:
- options
Object
- Options for rebuilding html.- onprocessinginstruction
Function
- Replace instruction with returned string. Default:function (name, value) { return "<" + value + ">"; }
- onopentag
Function
- Replace open tag with returned string. Default:function (name, attrs) { return "<" + name + createAttrStr(attrs) + ">"; }
- onclosetag
Function
- Replace close tag with returned string. Default:function (name, attrs) { return "</" + name + ">"; }
- ontext
Function
- Replace text with returned string. Default:function (value) { return value; }
- oncomment
Function
- Replace comment with returned string. Default:function (value) { return "<!--" + value + "-->"; }
- onprocessinginstruction
- options
rebuild.createAttrStr(attrs)
Helper for creating attribute.
- Params:
- attrs
Object
- A map of the attribute.
- attrs
- Returns:
String
- A string of the attribute starting with whitespace.