throw error for missing mark/node type

This commit is contained in:
Philipp Kühn
2021-05-03 09:50:57 +02:00
parent edb08bba4a
commit 80cf8bb71b
2 changed files with 8 additions and 0 deletions

View File

@@ -2,6 +2,10 @@ import { MarkType, Schema } from 'prosemirror-model'
export default function getMarkType(nameOrType: string | MarkType, schema: Schema): MarkType {
if (typeof nameOrType === 'string') {
if (!schema.marks[nameOrType]) {
throw Error(`There is no mark type named '${nameOrType}'. Maybe you forgot to add the extension?`)
}
return schema.marks[nameOrType]
}

View File

@@ -2,6 +2,10 @@ import { NodeType, Schema } from 'prosemirror-model'
export default function getNodeType(nameOrType: string | NodeType, schema: Schema): NodeType {
if (typeof nameOrType === 'string') {
if (!schema.nodes[nameOrType]) {
throw Error(`There is no node type named '${nameOrType}'. Maybe you forgot to add the extension?`)
}
return schema.nodes[nameOrType]
}