From be211dbc5cc8796e4ddf83fd3497d281125730c4 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Mon, 18 Mar 2024 22:54:27 -0400 Subject: [PATCH] fix: Table detection in isMarkdown, closes #6687 --- shared/editor/lib/isMarkdown.test.ts | 11 +++++++++++ shared/editor/lib/isMarkdown.ts | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/shared/editor/lib/isMarkdown.test.ts b/shared/editor/lib/isMarkdown.test.ts index 1891581ba8..cd771ef399 100644 --- a/shared/editor/lib/isMarkdown.test.ts +++ b/shared/editor/lib/isMarkdown.test.ts @@ -49,6 +49,17 @@ test("returns true for heading", () => { expect(isMarkdown(`### Heading 3`)).toBe(true); }); +test("returns false for table", () => { + expect( + isMarkdown(` +|NAME|TYPE|CLUSTER-IP|EXTERNAL-IP|PORT(S)|AGE| +|-|-|-|-|-|-| +|rancher-webhook|ClusterIP|10.43.198.97||443/TCP|258d| +|rancher|ClusterIP|10.43.50.214||80/TCP,443/TCP|258d| +`) + ).toBe(true); +}); + test("returns false for hashtag", () => { expect(isMarkdown(`Test #hashtag`)).toBe(false); expect(isMarkdown(` #hashtag`)).toBe(false); diff --git a/shared/editor/lib/isMarkdown.ts b/shared/editor/lib/isMarkdown.ts index 45bba3c21a..17954f4cb0 100644 --- a/shared/editor/lib/isMarkdown.ts +++ b/shared/editor/lib/isMarkdown.ts @@ -25,7 +25,7 @@ export default function isMarkdown(text: string): boolean { } // table header-ish - const tables = text.match(/^\|\s?[-]+\s?\|/gm); + const tables = text.match(/\|\s?[-]+\s?\|/gm); if (tables && tables.length > 1) { return true; }