feat(paste): support filter functions in tag-based paste config
Extend the paste processing logic to check filter functions when matching pasted elements to tools.
Previously, filter functions in pasteConfig.tags were only used during sanitization (via HTMLJanitor) but ignored during paste processing, causing all elements with a matching tag name to be treated as substitutable regardless of the filter.
Changes
- Add a
filterfield toTagSubstituteinterface - Store filter in
getTagsConfigwhen the sanitization config is a function - Add
isTagSubstitutablehelper that checks both tag name and filter - Update
processHTML,processElementNode, andcontainsAnotherToolTagsto use the helper
Example
A tool can now use a filter function in pasteConfig.tags to match only specific elements:
static get pasteConfig() {
return {
tags: {
SPAN: (el) => parseInt(el.style.fontWeight, 10) > 400
}
}
}
Previously, this filter was only checked during sanitization. Now it's also checked during paste processing, so only <span> elements that pass the filter will be assigned to the tool.
Closes #2959
Bumping this in case it got lost in the queue. The change is opt-in (filter functions are only used when configured), so existing paste configs are unaffected. Happy to address any feedback.