• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

callumacrae/gulp-w3cjs: w3cjs wrapper for gulp to validate your HTML

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

callumacrae/gulp-w3cjs

开源软件地址(OpenSource Url):

https://github.com/callumacrae/gulp-w3cjs

开源编程语言(OpenSource Language):

JavaScript 96.5%

开源软件介绍(OpenSource Introduction):

gulp-w3cjs NPM version Build Status Dependency Status

w3cjs wrapper for gulp to validate your HTML

Usage

First, install gulp-w3cjs as a development dependency:

npm install --save-dev gulp-w3cjs

Then, add it to your gulpfile.js:

var w3cjs = require('gulp-w3cjs');

gulp.task('w3cjs', function () {
	return gulp.src('src/*.html')
		.pipe(w3cjs())
		.pipe(w3cjs.reporter());
});

Custom Reporting

The results are also added onto each file object under w3cjs, containing success (Boolean) and messages (Array).

Example usage

var w3cjs = require('gulp-w3cjs');
var through2 = require('through2');

gulp.task('example', function () {
	return gulp.src('src/*.html')
		.pipe(w3cjs())
		.pipe(through2.obj(function(file, enc, cb){
			cb(null, file);
			if (!file.w3cjs.success){
				throw new Error('HTML validation error(s) found');
			}
		}));
});

Example output

HTML Error: index.html Line 5, Column 19: Element title must not be empty.
    <title></title>

.../gulpfile.js:11
                                throw new Error('HTML validation error(s) found');
                                      ^
Error: HTML validation error(s) found

API

w3cjs(options)

options.url

URL to the w3c validator. Use if you want to use a local validator. This is the same thing as w3cjs.setW3cCheckUrl().

options.proxy

Http address of the proxy server if you are running behind a firewall, e.g. http://proxy:8080

options.doctype and options.charset were dropped in 1.0.0. Use 0.3.0 if you need them.

options.showInfo

Default: false

Show info type messages in the output.

options.verifyMessage

Allows you to intercept info, warnings or errors, using options.verifyMessage methed, returning false will skip the log output. Example usage:

return gulp.src('index.html')
	.pipe(w3cjs({
		verifyMessage: function(type, message) {

			// prevent logging error message
			if(message.indexOf('Element “style” not allowed as child of element') === 0) return false;
			
			// allow message to pass through
			return true;
		}
	}))
	.pipe(w3cjs.reporter())

w3cjs.setW3cCheckUrl(url)

Same as options.url. SEt's the URL to the w3c validator.

License

MIT License




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap