Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[lexical-playground] [markdown] Fix: Block math equation is falsely converted to inline equation on MarkdownShortcutPlugin #6948

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/lexical-playground/src/nodes/EquationNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ export class EquationNode extends DecoratorNode<JSX.Element> {
this.__inline = inline ?? false;
}

isInline(): boolean {
return this.__inline;
}

static importJSON(serializedNode: SerializedEquationNode): EquationNode {
const node = $createEquationNode(
serializedNode.equation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,17 @@ export const EQUATION: TextMatchTransformer = {
if (!$isEquationNode(node)) {
return null;
}

return `$${node.getEquation()}$`;
const equation = node.getEquation();
const isInline = node.isInline();
return isInline ? `$${equation}$` : `$$${equation}$$`;
},
importRegExp: /\$([^$]+?)\$/,
regExp: /\$([^$]+?)\$$/,
importRegExp: /\$([^$]+?)\$|\$\$([^$]+?)\$\$/, // regex issue
regExp: /\$([^$]+?)\$$|\$\$([^$]+?)\$\$$/, // regex issue
replace: (textNode, match) => {
const [, equation] = match;
const equationNode = $createEquationNode(equation, true);
const [, inlineEquation, blockEquation] = match;
const equation = inlineEquation || blockEquation;
const isInline = !!inlineEquation;
const equationNode = $createEquationNode(equation, isInline);
textNode.replace(equationNode);
},
trigger: '$',
Expand Down
Loading