Is there a way to do something like forced layout with ProseMirror? Or even better, read-only parts of a document, where for example section titles would be fixed, but the rest would be editable?
Yes, ProseMirror can do these things. You’d use schema constraints to enforce the document starting with a heading, and if you want to make a node non-editable, you’d make it a leaf node and render it as uneditable content.
2 Likes
Amazing, thanks!
@marijn i’m trying to understand your suggestion and looking at the docs for content expressions, I thought it should be just as simple as this:
new Schema({
nodes: {
text: {},
title: {
content: "text",
toDOM() { return ["title", 0] },
parseDOM: [{tag: "title"}]
},
body: {
content: "text+",
toDOM() { return ["body", 0] },
parseDOM: [{tag: "body"}]
},
doc: {
content: "title body+"
}
}
})
But this doesn’t exactly work – care to elaborate on how one can do this?
You’ll want "text*"
, not "text"
or "text+"
. Also the body
and title
HTML tags already have a fixed meaning, so you can’t use them like that.