Skip to content

feat(paste): support filter functions in tag-based paste config#2999

Draft
costajohnt wants to merge 1 commit intocodex-team:nextfrom
costajohnt:feat/paste-filter-function
Draft

feat(paste): support filter functions in tag-based paste config#2999
costajohnt wants to merge 1 commit intocodex-team:nextfrom
costajohnt:feat/paste-filter-function

Conversation

@costajohnt
Copy link

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 filter field to TagSubstitute interface
  • Store filter in getTagsConfig when the sanitization config is a function
  • Add isTagSubstitutable helper that checks both tag name and filter
  • Update processHTML, processElementNode, and containsAnotherToolTags to 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

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Paste Config Improvement: add support for a filter function in pasteConfig to allow matching elements by attributes

1 participant