fix: Impossible to type more than one dollar symbol in a paragraph without triggering LaTeX (#5061)

This commit is contained in:
Tom Moor
2023-03-19 14:37:17 -04:00
committed by GitHub
parent 39eac5c6a6
commit 827c912887
3 changed files with 10 additions and 8 deletions

View File

@@ -2,7 +2,6 @@ import {
mathBackspaceCmd,
insertMathCmd,
makeInlineMathInputRule,
REGEX_INLINE_MATH_DOLLARS,
mathSchemaSpec,
} from "@benrbray/prosemirror-math";
import { PluginSimple } from "markdown-it";
@@ -21,7 +20,7 @@ import {
import { EditorState, Plugin } from "prosemirror-state";
import { MarkdownSerializerState } from "../lib/markdown/serializer";
import MathPlugin from "../plugins/Math";
import mathRule from "../rules/math";
import mathRule, { REGEX_INLINE_MATH_DOLLARS } from "../rules/math";
import { Dispatch } from "../types";
import Node from "./Node";
@@ -71,9 +70,9 @@ export default class Math extends Node {
}
toMarkdown(state: MarkdownSerializerState, node: ProsemirrorNode) {
state.write("$");
state.write("$$");
state.text(node.textContent, false);
state.write("$");
state.write("$$");
}
parseMarkdown() {

View File

@@ -1,13 +1,12 @@
import {
makeBlockMathInputRule,
REGEX_BLOCK_MATH_DOLLARS,
mathSchemaSpec,
} from "@benrbray/prosemirror-math";
import { PluginSimple } from "markdown-it";
import { NodeSpec, NodeType, Node as ProsemirrorNode } from "prosemirror-model";
import { EditorState } from "prosemirror-state";
import { MarkdownSerializerState } from "../lib/markdown/serializer";
import mathRule from "../rules/math";
import mathRule, { REGEX_BLOCK_MATH_DOLLARS } from "../rules/math";
import { Dispatch } from "../types";
import Node from "./Node";
@@ -36,10 +35,10 @@ export default class MathBlock extends Node {
}
toMarkdown(state: MarkdownSerializerState, node: ProsemirrorNode) {
state.write("$$\n");
state.write("$$$\n");
state.text(node.textContent, false);
state.ensureNewLine();
state.write("$$");
state.write("$$$");
state.closeBlock(node);
}

View File

@@ -2,6 +2,10 @@ import MarkdownIt from "markdown-it";
import StateBlock from "markdown-it/lib/rules_block/state_block";
import StateInline from "markdown-it/lib/rules_inline/state_inline";
export const REGEX_INLINE_MATH_DOLLARS = /\$\$(.+)\$\$/;
export const REGEX_BLOCK_MATH_DOLLARS = /\$\$\$\s+$/;
// test if potential opening or closing delimiter
// assumes that there is a "$" at state.src[pos]
function isValidDelimiter(state: StateInline, pos: number) {