Open susnux opened 2 years ago
ProseMirror does not allow marks of the same type to be nested like this. I guess the markdown parser could be a bit more graceful about this (just ignoring the inner opening and closing strong tokens).
ProseMirror does not allow marks of the same type to be nested like this.
Well one could workaround this as ProseMirror supports multiple marks of the same type if they have different attributes. Meaning you have to set excludes: ''
for the marks em
and strong
and add a nesting attribute to them.
e.g. something like this:
function nesting(...types) {
const fn = (node) => {
let el = (node as HTMLElement).parentElement
let nesting = 0
while(el !== null) {
if ([...arguments].includes(el.tagName)) nesting++
el = el.parentElement
}
return {nesting: nesting}
}
return fn
}
// ... inside the schema:
marks: {
em: {
attrs: {
nesting: {
default: null
}
},
parseDOM: [
{tag: "i", getAttrs: nesting("EM", "I")},
{tag: "em", getAttrs: nesting("EM", "I")},
],
toDOM() { return ["em"] },
excludes: ''
},
strong: {
excludes: '',
attrs: {
nesting: {
default: null
}
},
parseDOM: [
{tag: "b", getAttrs: nesting("STRONG", "B")},
{tag: "strong", getAttrs: nesting("STRONG", "B")},
],
toDOM() { return ["strong"] }
},
}
From CommonMark example 431:
should be parsed as:
Using just
markdown-it
this works as expected but thedefaultMarkdownParser
creates this incorrect representation: