Makes parser correctly identify unmatched opening tags #376
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.
When the parser attempts to determine if a closing token matches the latest parent on the stack, it only checks the node type and does not check the tag name. Early versions of markdoc used to include the tag name in the type attribute, but this condition wasn't updated when the tag became its own property.
This PR addresses issue #375 by updating the condition so that it checks to make sure that the
tag
name matches the value ofparent.tag
. This will make the check work as expected for opening and closing tags. For non-tag nodes, the value oftag
andparent.tag
should both beundefined
, so this approach should work as expected for all node types.In addition to fixing the issue, this PR also adds test cases to ensure that the structural errors are added to the AST for mismatched opening and closing tags, missing closing tags, and missing opening tags.