You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR implements a content model–based validation approach as discussed in #267, focusing on a small and practical subset of checks derived from the HTML specification.
What this PR does
This implementation checks whether child elements are allowed under a given parent based on its content model, without aiming for full structural validation.
It currently supports the following patterns:
Flow disallowed cases (simplest case)
Detects cases where flow content appears in places where flow content is not permitted.
Transparent content model (e.g. <a>)
Elements with a transparent content model delegate validation to their parent’s content model.
Specific tag patterns (e.g. <ul> → <li>)
Handles elements that only allow specific child tags.
Context-dependent patterns
Handles elements whose allowed content depends on context (e.g. <div>, <span>).
Custom elements and unknown elements
Since custom and unknown elements do not have an explicit content model, they are treated as allowing any content.
What this PR intentionally does not do
The following are intentionally out of scope for this PR:
Child element ordering
The order of children defined by a content model is not validated.
Descendant-level constraints
Rules that forbid specific elements anywhere in the descendant tree are not checked.
Validation under <head>
These cases are already covered by the existing html-head-only-elements and html-body-only-elements rules.
I’d be happy to adjust this if you have any feedback or suggestions. Thank you.
The commit ca3758b adds support for ERBBlockNode and ERBContentNode with the tag helper.
Extracting helper methods via regex is getting tricky.
Since a Prism-based approach isn’t available yet, should we wait for that, or keep extending the regex support for now?
Great, thank you so much for exploring this @kozy4324!
Since a Prism-based approach isn’t available yet, should we wait for that, or keep extending the regex support for now?
We can leave out the tag.div and content_tag and similar helpers in ERB for now. A lot of rules need to be updated once we have the tag detection working.
If you want, we can keep the tests and use test.fails("...", () => {}) so we know which ones to update later on.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR implements a content model–based validation approach as discussed in #267, focusing on a small and practical subset of checks derived from the HTML specification.
What this PR does
This implementation checks whether child elements are allowed under a given parent based on its content model, without aiming for full structural validation.
It currently supports the following patterns:
<a>)<ul>→<li>)<div>,<span>).What this PR intentionally does not do
The following are intentionally out of scope for this PR:
<head>html-head-only-elementsandhtml-body-only-elementsrules.I’d be happy to adjust this if you have any feedback or suggestions. Thank you.