sanitize-html
sanitize-html copied to clipboard
Allow tags in tags
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
- 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
- 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.