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

Allow tags in tags

Open cgorrieri opened this issue 1 year ago • 7 comments

The problem to solve

I would like to add a restriction on the content of a tag. For example, only allow BR tags in P or LI elements

Proposed solution

In allow tags, extend the list type of allow tags to a nested list with possible configurations like:

allowedTags: [
  'ul',
  ['li', { allowedTags: ['b', 'span', 'u', ...]}],
  ...
]

Alternatives

  1. We can use filters to parse the content of specific elements with a different parser. But it can conflict with the parent parser as the content will be parsed regardless by the main parser
  2. We can maybe update transformTags to get the text content and have the possibility to transform the content. But again, it can conflict with the main parser.

cgorrieri avatar Feb 27 '23 10:02 cgorrieri