validate-html-nesting
HTML nesting validator used by Vue.js Compiler
validate-html-nesting detects HTML nesting that causes browsers to modify the DOM structure. For example, placing an <hr> inside a <p> causes the browser to split the paragraph.
If your HTML looks like this
The browser will create DOM that looks like this
This mismatch between the DOM and the markup can cause issues in frameworks that assume the DOM matches the markup.
This library is designed to be used internally in frameworks who need to ensure rendered DOM matches authored markup - specially when the framework relies on compilation
This library is currently being used internally in Vue.js with 8M weekly downloads and by other frameworks directly with about 150k downloads weekly
API
Specify the parent element as the first argument and the child element as the second argument on the isValidHTMLNesting function.
Related
I also made Babel and ESLint plugins to validate JSX nesting at compile time - It can be used with any framework that uses JSX