How to exclude certain nodes from being part of the document

My editor uses { schema } from “prosemirror-schema-basic”.

As i don’t want images to be added or displayed anymore on it, i removed the node image from the schema nodes : `


` but i’m still getting images displayed by pasting them in the editor. How to prevent that ?

Did you use the result of the remove call to create a new schema, or did you expect it to change the existing schema? (In the latter case, that’s not how it works.)

1 Like

If you’re wanting to customize the schema, you’re probably ready to move away from using prosemirror-schema-basic directly. You can use that module as the basis for your new document and build from there. Once you master it, modifying your schema is one of the most enjoyable parts of using ProseMirror.

Start by looking at the source for prosemirror-schema-basic and you’ll notice that it’s just a single file about 150 lines long: prosemirror-schema-basic/schema-basic.js at master · ProseMirror/prosemirror-schema-basic · GitHub

In fact, many of those lines are comments. Use that structure as the basis for your new schema. If you’re wanting to remove images, find the nodes dictionary and remove the image entry. That’s it!

The doc node is your top-level node type for the whole document. In this case the document simply contains one or more block nodes. There is no node type called block, but several node types have group: "block",.

From there you can move on to modifying marks (e.g. you could remove “bold” functionality by removing the strong mark or add a new underline mark).

The important idea here is that you’re not modifying your document schema at runtime unless you have a really good reason to do so and you understand the implications of doing so. Otherwise, don’t be afraid to dig into the details. :smile:

1 Like

Thanks, i actually just have started from scratch with prosemirror couple of weeks ago and for now i’m trying to finish a project on deadlines. Otherwise sure i’m not afraid, i’m trying to dig from time time into PM internals and i wish i ll know all what’s under the hood soon :grinning:

1 Like