From 827c912887163e3060c1e89525b576bf2f5036c5 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Sun, 19 Mar 2023 14:37:17 -0400 Subject: [PATCH] fix: Impossible to type more than one dollar symbol in a paragraph without triggering LaTeX (#5061) --- shared/editor/nodes/Math.ts | 7 +++---- shared/editor/nodes/MathBlock.ts | 7 +++---- shared/editor/rules/math.ts | 4 ++++ 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/shared/editor/nodes/Math.ts b/shared/editor/nodes/Math.ts index 0a12e549d..a3800bad0 100644 --- a/shared/editor/nodes/Math.ts +++ b/shared/editor/nodes/Math.ts @@ -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() { diff --git a/shared/editor/nodes/MathBlock.ts b/shared/editor/nodes/MathBlock.ts index 8eba2eb4f..ea2042b87 100644 --- a/shared/editor/nodes/MathBlock.ts +++ b/shared/editor/nodes/MathBlock.ts @@ -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); } diff --git a/shared/editor/rules/math.ts b/shared/editor/rules/math.ts index 07d470f4e..50e367fe4 100644 --- a/shared/editor/rules/math.ts +++ b/shared/editor/rules/math.ts @@ -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) {