Hi, I’m currently trying to integrate MathJax into an editor, and began with inline math first. I created an input rule (/ $.+$ /), which, when triggered, created an inline_math node, defined here
inline_math: {
inline: true,
group: "inline",
attrs: {
texts: {}
},
draggable: true,
parseDOM: [{tag: "span"}],
toDOM(node) { return ["span", 0]}
},
which was linked to a NodeView, defined here.
export class InlineMathView {
...
constructor(node: Node, view: EditorView, getPos: () => number) {
this.node = node;
this.view = view;
this.getPos = getPos;
this.dom = document.createElement("span");
this.dom.appendChild(document.createTextNode(this.node.attrs.texts));
console.log(this.view);
console.log(this.getPos());
console.log(this.node.attrs.texts);
this.typesetter.typeset(this.dom);
}
}
So upon creation of the node, its content, which is set to $$, is typesetted and its content rendered into the DOM. Currently, the editor can correctly parse the ‘$’ delimiters and render the MathJax content, but upon pressing any character after the NodeView, the constructor is called again, as the content is typesetted again, as seen here. Also, when the NodeView is created again for more inline math on the same line, the other views’ constructors are called and are all re-rendered. I’m not too familiar with NodeViews currently, but I’m wondering what could be the cause of this problem?
Also, apologies if my last few posts have been vague or without much context. If there’s any more information needed for this post, however, please let me know.