htmlHint 应用安装

ou can learn how to use HTMLHint here.

Cli

  1. install & hint

    npm install htmlhint -g
    htmlhint -V
    htmlhint --help
    htmlhint www
    htmlhint www/test.html
    htmlhint www/**/*.xhtml
    htmlhint www/**/*.{htm,html}
    htmlhint http://www.alibaba.com/
    cat test.html | htmlhint stdin
    
  2. results

       test.html
          L5 |    </head>
                  ^ <title> must be present in <head> tag. (title-require)
          L8 |    </body>
                  ^ Tag must be paired, missing: [ </div> ], start tag match failed [ <div> ] on line 7. (tag-pair)
    
    2 errors in 1 files
    
  3. config rules

    search .htmlhintrc file in current directory and all parent directories:

    htmlhint
    htmlhint test.html
    

    custom config file:

    htmlhint --config htmlhint.conf test.html
    

    custom rules:

    htmlhint --rules tag-pair,id-class-value=underline test.html
    

    Inline rules in test.html:

    <!--htmlhint tag-pair,id-class-value:underline -->
    <html>
    <head>
        ...
    

JavaScript with node

  1. install

    npm install htmlhint --save
    
  2. Hint your html code:

    var HTMLHint  = require("htmlhint").HTMLHint;
    var messages = HTMLHint.verify('<ul><li></ul>', {'tag-pair': true});
    

JavaScript with browser

  1. Download: https://raw.github.com/yaniswang/HTMLHint/master/lib/htmlhint.js

  2. Hint your html code:

    <script type="text/javascript" src="htmlhint.js"></script>
    <script type="text/javascript">
        var messages = HTMLHint.verify('<ul><li></ul>', {'tag-pair': true});
    </script>
    

About Rules

Read more about all rules: Rules

If rules is undefined, it will use default ruleset:

{
    "tagname-lowercase": true,
    "attr-lowercase": true,
    "attr-value-double-quotes": true,
    "doctype-first": true,
    "tag-pair": true,
    "spec-char-escape": true,
    "id-unique": true,
    "src-not-empty": true,
    "attr-no-duplication": true,
    "title-require": true
}

About .htmlhintrc

You can config the `.htmlhintrc' like this, and place the file in your project root folder:

.htmlhintrc

{
    "tagname-lowercase": true,
    "attr-lowercase": true,
    "attr-value-double-quotes": true,
    "doctype-first": true
}

Load custom rules

rules/test-rule.js

module.exports = function(HTMLHint) {
    HTMLHint.addRule({
        id: 'test-rule',
        description: 'test rule.',
        init: function(parser, reporter){
            var self = this;
            parser.addListener('tagstart', function(event){
                var tagName = event.tagName.toLowerCase();
                if(tagName === 'body'){
                    reporter.warn('Found body.', event.line, event.col, self, event.raw);
                }
            });
        }
    });
};

Load rules:

htmlhint --rulesdir ./rules/ --rules test-rule

How to report bugs

You can create a new issue in GitHub and describe your problem or suggestion.

新建.htmlhintrc文件,内容如下:

{
  "tagname-lowercase": true,
  "attr-lowercase": true,
  "attr-value-double-quotes": true,
  "doctype-first": true,
  "tag-pair": true,
  "spec-char-escape": true,
  "id-unique": true,
  "src-not-empty": true,
  "attr-no-duplication": true,
  "title-require": true
}

 

转载于:https://my.oschina.net/joldy/blog/830045

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值