Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/manantank/validate-html-nesting
Validate parent-child nesting for HTML elements
https://github.com/manantank/validate-html-nesting
Last synced: 1 day ago
JSON representation
Validate parent-child nesting for HTML elements
- Host: GitHub
- URL: https://github.com/manantank/validate-html-nesting
- Owner: MananTank
- Created: 2022-05-13T14:15:34.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-04-23T07:43:06.000Z (over 1 year ago)
- Last Synced: 2024-11-11T18:52:41.506Z (9 days ago)
- Language: JavaScript
- Size: 157 KB
- Stars: 30
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# validate-html-nesting
A parent-child nesting validation library for HTML
This is not a full-blown HTML spec validation (intentionally). The parent-child nesting is considered valid if the Browser does not modify it, regardless of whether or not the HTML spec considers it valid or invalid. So, the library is purely for detecting the kind of element nesting which result in altered DOM.
### Example
```html
hello
```
The Browser modifies the above-shown structure to the below-shown structure, which is why the library considers the `p > hr` nesting invalid.
```html
hello
```And though `
` markup is technically invalid as per HTML spec, it's still considered valid because the browser does not modify it, so `h1 > div` nesting is considered valid by the library.
hi
## Install
```bash
npm i validate-html-nesting
```
## API
```javascript
isValidHTMLNesting(parentTag: string, childTag: string) : boolean
```
## Usage Example
```javascript
import { isValidHTMLNesting } from 'validate-html-nesting';isValidHTMLNesting('a', 'a'); // false
// because can not be child ofisValidHTMLNesting('p', 'hr'); // false
// because
can not be child of