Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handles self-closing tags #7

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

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