Add filterAttrs parameter to toJSON methods #86

Closed
YaoKaiLun wants to merge 1 commit from add-filterAttrs-for-toJSON into master
YaoKaiLun commented 2024-12-06 02:09:51 +01:00 (Migrated from github.com)

Support to filter useless attrs, like undefind or null

doc.toJSON(attrs => _.omitBy(attrs, _. isNil))
Support to filter useless attrs, like undefind or null ``` doc.toJSON(attrs => _.omitBy(attrs, _. isNil)) ```
marijnh commented 2024-12-06 07:42:22 +01:00 (Migrated from github.com)

I don't think this is a critical enough feature to include here. You could implement this as a post-processing pass on the JSON output if you really need it.

Where are these stray attrs coming from, in your system?

I don't think this is a critical enough feature to include here. You could implement this as a post-processing pass on the JSON output if you really need it. Where are these stray attrs coming from, in your system?
YaoKaiLun commented 2024-12-06 08:11:15 +01:00 (Migrated from github.com)

@marijnh You're right. it indeed isn't a critical feature. Thank you for your reply!

These stray attrs came from tiptap which uses addAttributes to declare node attributes and also as initial values.
github.com/ueberdosis/tiptap@7567acebd6/packages/extension-image/src/image.ts (L77)

export const Image = Node.create<ImageOptions>({
  ...
  addAttributes() {
    return {
      src: {
        default: null,
      },
      alt: {
        default: null,
      },
      title: {
        default: null,
      },
    }
  },
@marijnh You're right. it indeed isn't a critical feature. Thank you for your reply! These stray attrs came from tiptap which uses `addAttributes` to declare node attributes and also as initial values. https://github.com/ueberdosis/tiptap/blob/7567acebd62a23a2820d67a500bc5009a1099bdb/packages/extension-image/src/image.ts#L77 ``` export const Image = Node.create<ImageOptions>({ ... addAttributes() { return { src: { default: null, }, alt: { default: null, }, title: { default: null, }, } }, ```
marijnh commented 2024-12-06 09:43:27 +01:00 (Migrated from github.com)

Yeah, that seems more of a Tiptap problem then. I'm going to close this, and recommend you handle this outside of the core lib.

Yeah, that seems more of a Tiptap problem then. I'm going to close this, and recommend you handle this outside of the core lib.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
prosemirror/prosemirror-model!86
No description provided.