https://github.com/bjoern-hempel/node-unclosed-tag-finder
Checks unclosed html5 tags, that are normally optional
https://github.com/bjoern-hempel/node-unclosed-tag-finder
checker coding-style html html5 mit-license nodejs xml
Last synced: 2 months ago
JSON representation
Checks unclosed html5 tags, that are normally optional
- Host: GitHub
- URL: https://github.com/bjoern-hempel/node-unclosed-tag-finder
- Owner: bjoern-hempel
- License: mit
- Created: 2017-06-16T14:34:13.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-06-26T12:12:48.000Z (almost 8 years ago)
- Last Synced: 2024-12-27T03:13:13.686Z (4 months ago)
- Topics: checker, coding-style, html, html5, mit-license, nodejs, xml
- Language: JavaScript
- Size: 20.5 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Unclosed Tag Finder
A library that finds unclosed html5 tags that are normally optional (via W3C check). These optional tags could be:
- html
- head
- body
- p
- dt
- dd
- li
- option
- thead
- th
- tbody
- tr
- td
- tfoot
- colgroup## Installation
```
user$ npm install unclosed-tag-finder -g
```## Usage (the command line version)
### Create a valid html5 file (but with some unclosed tags)
```
user$ vi valid-utf8-unclosed.html
``````
Das sind Umlaute: öäü
Das ist ein Test.
äöü
- 123
```
### Check the html5 file with a w3c checker of your choice
```
user$ npm install html-validator-cli -g
user$ html-validator --file=valid-utf8-unclosed.html
Page is valid
```
or
```
user$ xmllint --html --noout valid-utf8-unclosed.html
```
The page is valid.
### Find unclosed tags within this valid html5 file
```
user$ unclosed-tag-finder valid-utf8-unclosed.html
valid-utf8-unclosed.html:7 (missing close tag:
opening tag:
valid-utf8-unclosed.html:10 (missing close tag:
)opening tag:
valid-utf8-unclosed.html:12 (missing close tag:
opening tag:
```
Although the html file is valid, we found some unclosed html5 tags.
## Use this library inside your own scripts
```js
#!/usr/bin/env node
/* load some libraries */
var unclosedTagFinder = require('unclosed-tag-finder');
var fs = require('fs');
var finder = new unclosedTagFinder.builder();
/* check command line arguments */
if (process.argv.length < 3) {
console.error('No file to validate was given. Abort..');
process.exit(1);
}
/* read given file */
fs.readFile(process.argv[2], 'utf-8', function(err, html) {
if (err) {
console.log(err);
process.exit(1);
return;
}
var unclosedTags = finder.getUnclosedTags(html, process.argv[2]);
if (unclosedTags.length == 0) {
return;
}
/* prints out missing close tag issues */
for (var i = 0; i < unclosedTags.length; i++) {
if (unclosedTags[i].hasNoCloseTag) {
console.info(unclosedTags[i].filename + ':' + unclosedTags[i].line + ' (missing close tag: <' + unclosedTags[i].name + '/>)');
console.info(unclosedTags[i].tag);
console.info('');
}
}
/* prints out missing open tag issues */
for (var i = 0; i < unclosedTags.length; i++) {
if (unclosedTags[i].hasNoOpenTag) {
console.info(unclosedTags[i].filename + ':' + unclosedTags[i].line + ' (missing open tag: <' + unclosedTags[i].name + '>)');
console.info(unclosedTags[i].tag);
console.info('');
}
}
});
```
```
user$ chmod 775 listUnclosedTags.js
```
Now check the file with the listUnclosedTags.js script:
```
user$ ./listUnclosedTags.js valid-utf8-unclosed.html
valid-utf8-unclosed.html:7 (missing close tag:
opening tag:
valid-utf8-unclosed.html:10 (missing close tag:
)
opening tag:
valid-utf8-unclosed.html:12 (missing close tag:
opening tag:
```
## More informations and source code
You will find more informations and the source code at [GitHub](https://github.com/bjoern-hempel/node-unclosed-tag-finder).
For an executable npm package please have a look at [npmjs.com](https://www.npmjs.com/package/unclosed-tag-finder).
## License
ISC © [Björn Hempel](https://www.ixno.de)