textBlock
is a group name. The simpleAnswer
's content
is defined as one or more textBlock
s, and several nodes (paragraph, lists) are declared to be part of the textBlock
group.
There is another answer
group, that allows to nest any answers (simpleAnswer
or switchAnswer
) into switchCase
s of switchAnswer
s.
Sorry that I didn’t included the full schema:
nodes: {
doc: {content: 'answer+'},
switchAnswer: {
TAG: 'section',
toDOM(node) {
return [node.type.spec.TAG, 0];
},
parseDOM: [{tag: 'section'}],
group: 'answer',
content: 'switchCase+',
},
switchCase: {
TAG: 'article',
attrs: {case: {default: 'default'}, timestamp: {default: undefined}},
toDOM(node) {
return [node.type.spec.TAG, {case: node.attrs.case}, 0];
},
parseDOM: [{tag: 'article'}],
content: 'answer+',
},
simpleAnswer: {
TAG: 'div',
toDOM(node) {
return [node.type.spec.TAG, {class: 'simple'}, 0];
},
parseDOM: [{tag: 'div[class="simple"]'}],
group: 'answer',
content: 'textBlock+',
},
paragraph: {
TAG: 'p',
toDOM(node) {
return [node.type.spec.TAG, 0];
},
parseDOM: [{tag: 'p'}],
group: 'textBlock',
content: 'text*',
marks: '_', // any mark
},
unorderedList: {
TAG: 'ul',
content: 'listItem+',
toDOM(node) {
return [node.type.spec.TAG, 0];
},
group: 'textBlock',
parseDOM: [{tag: 'ul'}],
},
orderedList: {
TAG: 'ol',
content: 'listItem+',
toDOM(node) {
return [node.type.spec.TAG, 0];
},
group: 'textBlock',
parseDOM: [{tag: 'ol'}],
},
listItem: {
TAG: 'li',
content: 'text*',
toDOM(node) {
return [node.type.spec.TAG, 0];
},
parseDOM: [{tag: 'li'}],
},
text: {inline: true},
image: {
TAG: 'img',
toDOM(node) {
return [node.type.spec.TAG, 0];
},
parseDOM: [{tag: 'img'}],
inlineContent: true,
},
},
marks: {
bold: {
TAG: 'b',
parseDOM: [
{
tag: 'b',
getAttrs(node: any) {
return node.style && node.style.fontWeight !== 'normal' && null;
},
},
{tag: 'strong'},
{
style: 'font-weight',
getAttrs(value) {
return typeof value === 'string' && /^(bold(er)?|[5-9]\d{2,})$/.test(value) && null;
},
},
],
toDOM(node) {
return [node.type.spec.TAG, 0];
},
},
italic: {
TAG: 'em',
parseDOM: [{tag: 'i'}, {tag: 'em'}, {style: 'font-style=italic'}],
toDOM(node) {
return [node.type.spec.TAG, 0];
},
},
link: {
TAG: 'a',
parseDOM: [
{
tag: 'a[href]',
getAttrs(dom) {
if (dom instanceof Element) {
return {
href: dom.getAttribute('href'),
title: dom.getAttribute('title'),
target: {default: '_blank'},
};
} else {
return false;
}
},
},
],
attrs: {href: {}, target: {default: '_blank'}},
toDOM(node) {
return [node.type.spec.TAG, {href: node.attrs.href, title: node.attrs.href, target: node.attrs.target}, 0];
},
},
},