I have customized a figure node.
figure: {
attrs: { src: "" },
group: "block",
marks: "",
content: "inline*",
parseDOM: [
{
tag: "img[src]",
getAttrs(dom) {
return {
src: dom.getAttribute("src")
};
}
},
{
tag: "figure",
contentElement: "figcaption",
getAttrs(dom) {
let img = dom.querySelector("img");
return { src: img ? img.src : null };
}
}
],
toDOM(node) {
return ["figure", ["img", { src: node.attrs.src }], ["figcaption", 0]];
}
}
And the rendered html:
<figure>
<img src="example.jpg" />
<figcaption>This is description</figcaption>
</figure>
Suppose the cursor is after “is”, press Enter
.
The expected result is
<figure>
<img src="example.jpg" />
<figcaption>This is</figcaption>
</figure>
<p> description</p>
But actually it is
<figure>
<img src="example.jpg" />
<figcaption>This is</figcaption>
</figure>
<figure>
<img src="example.jpg" />
<figcaption> description</figcaption>
</figure>
How can I get the expected results?