Make math node handling better
This commit is contained in:
parent
78746938b7
commit
cd47c79d86
2 changed files with 15 additions and 7 deletions
|
|
@ -36,7 +36,9 @@ export const MathBlock = Node.create({
|
||||||
return {
|
return {
|
||||||
text: {
|
text: {
|
||||||
default: "",
|
default: "",
|
||||||
parseHTML: (element) => element.innerHTML.split("$")[1],
|
parseHTML: (element) => {
|
||||||
|
return element.innerHTML;
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
@ -44,7 +46,7 @@ export const MathBlock = Node.create({
|
||||||
parseHTML() {
|
parseHTML() {
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
tag: "div",
|
tag: `div[data-type="${this.name}"]`,
|
||||||
getAttrs: (node: HTMLElement) => {
|
getAttrs: (node: HTMLElement) => {
|
||||||
return node.hasAttribute("data-katex") ? {} : false;
|
return node.hasAttribute("data-katex") ? {} : false;
|
||||||
},
|
},
|
||||||
|
|
@ -55,8 +57,8 @@ export const MathBlock = Node.create({
|
||||||
renderHTML({ HTMLAttributes }) {
|
renderHTML({ HTMLAttributes }) {
|
||||||
return [
|
return [
|
||||||
"div",
|
"div",
|
||||||
{},
|
{ "data-type": this.name, "data-katex": true },
|
||||||
["div", { "data-katex": true }, `$$${HTMLAttributes.text}$$`],
|
`${HTMLAttributes.text}`,
|
||||||
];
|
];
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,9 @@ export const MathInline = Node.create<MathInlineOption>({
|
||||||
return {
|
return {
|
||||||
text: {
|
text: {
|
||||||
default: "",
|
default: "",
|
||||||
parseHTML: (element) => element.innerHTML.split("$")[1],
|
parseHTML: (element) => {
|
||||||
|
return element.innerHTML;
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
@ -45,7 +47,7 @@ export const MathInline = Node.create<MathInlineOption>({
|
||||||
parseHTML() {
|
parseHTML() {
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
tag: "span",
|
tag: `span[data-type="${this.name}"]`,
|
||||||
getAttrs: (node: HTMLElement) => {
|
getAttrs: (node: HTMLElement) => {
|
||||||
return node.hasAttribute("data-katex") ? {} : false;
|
return node.hasAttribute("data-katex") ? {} : false;
|
||||||
},
|
},
|
||||||
|
|
@ -54,7 +56,11 @@ export const MathInline = Node.create<MathInlineOption>({
|
||||||
},
|
},
|
||||||
|
|
||||||
renderHTML({ HTMLAttributes }) {
|
renderHTML({ HTMLAttributes }) {
|
||||||
return ["span", { "data-katex": true }, `$${HTMLAttributes.text}$` || {}];
|
return [
|
||||||
|
"span",
|
||||||
|
{ "data-type": this.name, "data-katex": true },
|
||||||
|
`${HTMLAttributes.text}`,
|
||||||
|
];
|
||||||
},
|
},
|
||||||
|
|
||||||
addNodeView() {
|
addNodeView() {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue