Skip to content

Conversation

@doingandlearning
Copy link

(area|base|br|col|...|wbr): Matches any of the listed void element tags.

([^>]*?): Captures any attributes inside the tag, if present.

(?<!/)>: A negative lookbehind assertion that matches a > only if it's not preceded by a /. This ensures we don't modify already self-closing tags.

</\1>|: Matches the closing tag if present (which should be rare or non-existent for these elements). The \1 is a backreference to the matched tag name, ensuring we're matching the correct closing tag.

The replacement pattern "<$1$2 />" puts the tag and any attributes into the self-closing format.

With this transformation, all the listed void elements will be made self-closing if they aren't already.

(area|base|br|col|...|wbr): Matches any of the listed void element tags.

([^>]*?): Captures any attributes inside the tag, if present.

(?<!\/)>: A negative lookbehind assertion that matches a > only if it's not preceded by a /. This ensures we don't modify already self-closing tags.

<\/\1>|: Matches the closing tag if present (which should be rare or non-existent for these elements). The \1 is a backreference to the matched tag name, ensuring we're matching the correct closing tag.

The replacement pattern "<$1$2 />" puts the tag and any attributes into the self-closing format.

With this transformation, all the listed void elements will be made self-closing if they aren't already.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant