-
Notifications
You must be signed in to change notification settings - Fork 368
feat: ability to specify if selfClosing element is a void element #670
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
base: main
Are you sure you want to change the base?
Conversation
I didn't change the documentation because I don't know where to write about |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great — just one request to avoid prototype pollution issues.
As for documentation, please introduce a new third-level heading.
index.js
Outdated
const tagAllowed = function (name) { | ||
const { selfClosing } = options; | ||
if (Array.isArray(selfClosing)) { | ||
options.selfClosing = selfClosing.reduce((before, tagName) => ({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be more performant to use a for loop here, avoiding the need to make a new object on every pass.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i replaced the reduce with a for-of loop
index.js
Outdated
if (options.selfClosing.indexOf(name) !== -1) { | ||
result += ' />'; | ||
|
||
if (options.selfClosing[name]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use Object.hasOwn(options.selfClosing, name)
to make sure it's a real property and not something sneaky like __prototype__
. Or use a Map
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
options.parser = Object.assign({}, htmlParserDefaults, options.parser); | ||
|
||
const tagAllowed = function (name) { | ||
const { selfClosing } = options; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Localized and then never used in a localized away again because of the reassignment for the array case. So I think it would be clearer if we didn't do this at all and just referred to options.selfClosing
throughout this bit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The README must be updated to cover this new syntax.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delay on this one!
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Bump to remove label. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
I know this has been a long back and forth, but do you know if you will be able to finish this @gastonyte? |
Summary
That PR is about adding ability for users to not add a
/
at the end of specific void elements (like<br>
,<link>
or<input>
elements)This change originally come from #51
What are the specific steps to test this change?
What kind of change does this PR introduce?
(Check at least one)
Make sure the PR fulfills these requirements:
If adding a new feature without an already open issue, it's best to open a feature request issue first and wait for approval before working on it.
Other information: