feat(paste): support filter functions in tag-based paste config - #2999
feat(paste): support filter functions in tag-based paste config#2999costajohnt wants to merge 3 commits into
Conversation
|
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. |
neSpecc
left a comment
There was a problem hiding this comment.
Overall seems ok. Please, add a corresponded test case. And write a line in a changelog
d5fa0e7 to
36ce01b
Compare
|
Totally understand if priorities have shifted here. Let me know if this is still something you'd consider, otherwise I'm happy to close it out. |
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. Add a filter field to TagSubstitute, store it in getTagsConfig when the sanitization config is a function, and introduce isTagSubstitutable that checks both tag name and filter. Update processHTML, processElementNode, and containsAnotherToolTags to use the helper. Closes codex-team#2959
Adds Cypress test exercising both branches of the filter function (accept and reject), and a 2.31.6 changelog entry.
The processElementNode refactor left a dead `const tags = ...` line that broke `yarn lint`. Remove it. The new filter-function Cypress test passed pasteConfig parsing but failed visually because the test's FilteredDivTool only assigned to `this.data` in onPaste, never updating the rendered element. Editor.js calls render() once at block creation and dispatches onPaste later via requestIdleCallback (paragraph tool follows the same pattern). Track the rendered element and mutate its textContent in onPaste so the asserted "Accepted" text shows up.
04547cf to
47e2e0b
Compare
|
Hi @neSpecc, following up on your review. Both asks are in, I just never said so here, sorry about that.
I've also rebased onto current |
Extend the paste processing logic to check filter functions when matching pasted elements to tools.
Previously, filter functions in
pasteConfig.tagswere 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
filterfield toTagSubstituteinterfacegetTagsConfigwhen the sanitization config is a functionisTagSubstitutablehelper that checks both tag name and filterprocessHTML,processElementNode, andcontainsAnotherToolTagsto use the helperExample
A tool can now use a filter function in
pasteConfig.tagsto match only specific elements: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