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

How to extends image node to accept 2 attributes? #4

Open
jet10000 opened this issue Jul 22, 2020 · 4 comments
Open

How to extends image node to accept 2 attributes? #4

jet10000 opened this issue Jul 22, 2020 · 4 comments

Comments

@jet10000
Copy link

jet10000 commented Jul 22, 2020

uploadID missing.

I'm using prosemirror-schema-basic

How to extends image node to accept 2 attributes in my code?

@OrkhanAlikhanov
Copy link
Owner

Can you elaborate? What are you trying to achieve?

@jet10000
Copy link
Author

I want to use prosemirror-image-uploader in my code, I found image uploadID is null, Maybe need extends image node schema? But how to do it?

@jet10000
Copy link
Author

How should I place the code? or I need to modify these codes directly in the prosemirror-schema-basic library?

{
  image: {
    attrs: {
      src: {},
      alt: { default: null },
      title: { default: null },
      uploadId: { default: null }, /// added
      error: { default: null }   /// added
    },
    parseDOM: [{tag: 'img[src]', getAttrs(dom) {
      return {
        src: dom.getAttribute('src'),
        title: dom.getAttribute('title'),
        alt: dom.getAttribute('alt'),
        uploadId: dom.getAttribute('uploadId'), /// added
        error: dom.getAttribute('error') /// added
      }
    }}],
    toDOM(node) { 
      let { src, alt, title, uploadId, error } = node.attrs;  /// updated
      return ['img', { src, alt, title, uploadId, error }] /// updated
    }
  },
}

@OrkhanAlikhanov
Copy link
Owner

Here is a minimal working sandbox. Check it out

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

No branches or pull requests

2 participants