From 72010e5b7add6357adc7f81455cebc4615f6c902 Mon Sep 17 00:00:00 2001 From: Lars Wrenger Date: Wed, 14 Feb 2024 23:17:28 +0100 Subject: [PATCH 1/2] Improve support for lists --- src/api.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/api.ts b/src/api.ts index 2532721..b880418 100644 --- a/src/api.ts +++ b/src/api.ts @@ -19,8 +19,14 @@ export async function getDetectionResult( if (/^`[^`]+`$/.test(text)) { return text; } + const linebreaks = '\n'.repeat(text.match(/\n/g)?.length ?? 0); - return '\n'.repeat((text.match(/\n/g) || []).length); + // Support lists (annotation ends with marker) + if (text.match(/^\s*(-|\d+\.) $/m)) { + return linebreaks + '• '; // this is the character, the online editor uses + } + + return linebreaks; }, }); From e466cea9c9550371df433d5530770e64081b3e79 Mon Sep 17 00:00:00 2001 From: Clemens Date: Sun, 18 Feb 2024 15:43:55 +0100 Subject: [PATCH 2/2] update regex matching according to linting rules --- src/api.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/api.ts b/src/api.ts index b880418..477509f 100644 --- a/src/api.ts +++ b/src/api.ts @@ -7,6 +7,7 @@ import { LanguageToolPluginSettings } from './SettingsTab'; export const logs: string[] = []; let lastStatus: 'ok' | 'request-failed' | 'request-not-ok' | 'json-parse-error' = 'ok'; +const listRegex = /^\s*(-|\d+\.) $/m; export async function getDetectionResult( text: string, @@ -19,11 +20,11 @@ export async function getDetectionResult( if (/^`[^`]+`$/.test(text)) { return text; } - const linebreaks = '\n'.repeat(text.match(/\n/g)?.length ?? 0); + const linebreaks = '\n'.repeat((text.match(/\n/g) || [])?.length ?? 0); // Support lists (annotation ends with marker) - if (text.match(/^\s*(-|\d+\.) $/m)) { - return linebreaks + '• '; // this is the character, the online editor uses + if (listRegex.exec(text)) { + return `${linebreaks}• `; // this is the character, the online editor uses } return linebreaks; @@ -107,7 +108,10 @@ export async function getDetectionResult( } catch (e) { const status = 'request-failed'; if (lastStatus !== status || !settings.shouldAutoCheck) { - new Notice(`Request to LanguageTool server failed. Please check your connection and LanguageTool server URL`, 3000); + new Notice( + `Request to LanguageTool server failed. Please check your connection and LanguageTool server URL`, + 3000, + ); lastStatus = status; } return Promise.reject(e);