I try to write mostly valid polyglot (X)HTML 5 in my angular HTML templates. They look something like this:
<div class="some-class">
<input type="checkbox" data-ng-model="variable" />
<foo-directive data-ng-if="variable"></foo-directive>
</div>
Sometimes I forget closing a tag properly which breaks some browsers. So I would like to include a validator in my toolchain.
The problem is: I do not know of a validator that can handle this case. XML validators typically require a DTD, HTML validators will complain about the angular directives that are used in the code.
Maybe validator is the wrong word and I really want a linter. The only real thing I want it to do is to check that every opening tag has a matching closing tag. Everything else is a bonus.
Do you know of such a validator?
NOTE: I primarily do search for a command line tool that I can integrate with my automated testing. But a webservice might be helpful, too.
To add validation to a template-driven form, you add the same validation attributes as you would with native HTML form validation. Angular uses directives to match these attributes with validator functions in the framework.
The HTMLSelectElement. checkValidity() method checks whether the element has any constraints and whether it satisfies them. If the element fails its constraints, the browser fires a cancelable invalid event at the element, and then returns false .
Almost all HTML syntax is valid template syntax. However, because an Angular template is part of an overall webpage, and not the entire page, you don't need to include elements such as <html> , <body> , or <base> , and can focus exclusively on the part of the page you are developing.
Since htmlhint is an option, you can use it as described here from command line (of course you will have to npm install
it first and make sure your PATH
contains node_modules/.bin
):
htmlhint test.html
To test for specific options:
htmlhint -r tag-pair,attr-no-duplication test.html
Or if the options are in a configuration file:
htmlhint -c config-file test.html
I use the following options with Angular:
tag-pair
: make sure tags are closed properlyattr-no-duplication
: no duplicate attributes in an elementIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With