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

Allow tags in tags #609

Open
cgorrieri opened this issue Feb 27, 2023 · 7 comments
Open

Allow tags in tags #609

cgorrieri opened this issue Feb 27, 2023 · 7 comments

Comments

@cgorrieri
Copy link

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.
@stale
Copy link

stale bot commented May 21, 2023

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 stale bot added the stale label May 21, 2023
@stale stale bot closed this as completed Jun 10, 2023
@cgorrieri
Copy link
Author

This could be useful to clean nested elements, let's keep it open

@icarns
Copy link

icarns commented Apr 15, 2024

@cgorrieri Did you manage to solve this problem? Given

<p>
  <p>
    Some incorrectly nested text
  </p>
</p>

I'd love to be able to get

<p>
  Some incorrectly nested text
</p>

After sanitizing the HTML string.

@boutell
Copy link
Member

boutell commented Apr 15, 2024

The proposal is a good one. Not 100% sure about the syntax, I'm curious what @BoDonkey thinks.

This isn't a requirement we have in-house so I'll reopen it and tag it contributions welcome.

@cgorrieri
Copy link
Author

In my case I ended up doing a regex before parsing to remove the tags I didn't want nested.

@BoDonkey
Copy link
Contributor

I like the idea of this new feature. IMO, whoever tackles it will need to be careful with both backward compatibility and not requiring the developer to utilize the feature. So, it should not be a list of defaults and the ability to modify those defaults, as is currently implemented for allowedTags. It just seems like there are too many edge cases to provide sensible defaults.

@boutell
Copy link
Member

boutell commented Apr 16, 2024

The existing syntax must continue to work, yes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants