sanitize-html icon indicating copy to clipboard operation
sanitize-html copied to clipboard

feat: ability to specify if selfClosing element is a void element

Open gastonyte opened this issue 1 year ago • 5 comments

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 https://github.com/apostrophecms/sanitize-html/issues/51

What are the specific steps to test this change?

type SelfClosingOptions = Record<string, boolean | { voidElement: boolean }>

type MyIOptions = Omit<sanitizeHtml.IOptions, 'selfClosing'> & {
  selfClosing?: SelfClosingOptions | string[] | undefined
}

const sanitizationOptions: MyIOptions = {
  allowedTags: ['p', 'strong', 'em', 'u', 's', 'blockquote', 'ul', 'ol', 'li', 'br'],
  allowedAttributes: {},
  selfClosing: {
    br: {
      voidElement: true
    }
  },
}

const cleaned = sanitizeHtml(
  value,
  sanitizationOptions as sanitizeHtml.IOptions
)

What kind of change does this PR introduce?

(Check at least one)

  • [ ] Bug fix
  • [x] New feature
  • [ ] Refactor
  • [ ] Documentation
  • [ ] Build-related changes
  • [ ] Other

Make sure the PR fulfills these requirements:

  • [ ] It includes a) the existing issue ID being resolved, b) a convincing reason for adding this feature, or c) a clear description of the bug it resolves
  • [ ] The changelog is updated
  • [ ] Related documentation has been updated
  • [x] Related tests have been updated

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:

gastonyte avatar Jul 29 '24 20:07 gastonyte

I didn't change the documentation because I don't know where to write about voidElement because the section explaining selfClosing does not exist yet.

gastonyte avatar Jul 29 '24 20:07 gastonyte

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.

stale[bot] avatar Apr 26 '25 02:04 stale[bot]

Bump to remove label.

BoDonkey avatar May 08 '25 13:05 BoDonkey

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.

stale[bot] avatar Jul 19 '25 01:07 stale[bot]

I know this has been a long back and forth, but do you know if you will be able to finish this @gastonyte?

BoDonkey avatar Jul 19 '25 09:07 BoDonkey