From 5d09be4addf585d458faebaba2806f8a6a4e9aed Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Mon, 2 Dec 2024 22:28:59 -0500 Subject: [PATCH] More improvements to LaTeX fence detection --- shared/editor/lib/isMarkdown.test.ts | 7 ++++++- shared/editor/lib/isMarkdown.ts | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/shared/editor/lib/isMarkdown.test.ts b/shared/editor/lib/isMarkdown.test.ts index 29b6b85b03..f0232c50af 100644 --- a/shared/editor/lib/isMarkdown.test.ts +++ b/shared/editor/lib/isMarkdown.test.ts @@ -36,7 +36,12 @@ this is code }); test("returns true for latex fence", () => { - expect(isMarkdown(`\$\$i\$\$`)).toBe(true); + expect(isMarkdown(`\$i\$`)).toBe(true); + expect( + isMarkdown(`\$0.00 +random content +\$1.00`) + ).toBe(false); }); test("returns false for non-closed fence", () => { diff --git a/shared/editor/lib/isMarkdown.ts b/shared/editor/lib/isMarkdown.ts index 43cd9db656..4909a63686 100644 --- a/shared/editor/lib/isMarkdown.ts +++ b/shared/editor/lib/isMarkdown.ts @@ -10,8 +10,8 @@ export default function isMarkdown(text: string): boolean { } // latex-ish - const latex = text.match(/\$\$/gm); - if (latex && latex.length > 1) { + const latex = text.match(/\$(.+)\$/g); + if (latex && latex.length > 0) { signals += latex.length; }