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
<!DOCTYPE html>
<html>
<head>
<title>Das sind Umlaute: öäü</title>
</head>
<body>
<p
class="test"
>Das ist ein Test.<br />
<p>äöü
<ul>
<li>123
</ul>
</body>
</html>
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: <p/>)
opening tag: <p
class="test"
>
valid-utf8-unclosed.html:10 (missing close tag: <p/>)
opening tag: <p>
valid-utf8-unclosed.html:12 (missing close tag: <li/>)
opening tag: <li>
Although the html file is valid, we found some unclosed html5 tags.
Use this library inside your own scripts
#!/usr/bin/env node /* load some libraries */var unclosedTagFinder = ;var fs = ; var finder = ; /* check command line arguments */if processargvlength < 3 console; process; /* read given file */fs;
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: <p/>)
opening tag: <p
class="test"
>
valid-utf8-unclosed.html:10 (missing close tag: <p/>)
opening tag: <p>
valid-utf8-unclosed.html:12 (missing close tag: <li/>)
opening tag: <li>
More informations and source code
You will find more informations and the source code at GitHub.
For an executable npm package please have a look at npmjs.com.
License
ISC © Björn Hempel