From ed3c3fec90637611c25b86d9c9eb1025dbb4a41c Mon Sep 17 00:00:00 2001 From: Peter Kaufman Date: Fri, 25 Oct 2024 19:03:24 -0400 Subject: [PATCH] fixed an issue with list items getting thier list item proceeding space removed in nested blockquotes/callouts --- __tests__/remove-multiple-spaces.test.ts | 29 ++++++++++++++++++++++++ src/rules/remove-multiple-spaces.ts | 11 +++++++-- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/__tests__/remove-multiple-spaces.test.ts b/__tests__/remove-multiple-spaces.test.ts index 917fd6ad..32bbc8ac 100644 --- a/__tests__/remove-multiple-spaces.test.ts +++ b/__tests__/remove-multiple-spaces.test.ts @@ -210,6 +210,35 @@ ruleTest({ $ x = 2y $ `, }, + { // accounts for https://github.com/platers/obsidian-linter/issues/1203 + testName: 'A nested callout/blockquote should not have list item proceeding space removed', + before: dedent` + > [!goal]+ Two goals of object-oriented design + > + > > [!def]- Cohesion + > > - How strongly related the parts are inside a class + > > - About a class + > > - A class is *cohesive* if the data and behaviour of these objects makes sense + > > - **High cohesion**: + > > - A class does one job, and does it well + > > - **Low cohesion**: + > > - Class has parts that do not relate to each other + > > - e.g., \`Customer\` class might have \`getName\`, \`getAddress\`, but also \`sendEmail\` that sends an email to the customer → Weird; not a major responsibility of the customer → ==not cohesive + `, + after: dedent` + > [!goal]+ Two goals of object-oriented design + > + > > [!def]- Cohesion + > > - How strongly related the parts are inside a class + > > - About a class + > > - A class is *cohesive* if the data and behaviour of these objects makes sense + > > - **High cohesion**: + > > - A class does one job, and does it well + > > - **Low cohesion**: + > > - Class has parts that do not relate to each other + > > - e.g., \`Customer\` class might have \`getName\`, \`getAddress\`, but also \`sendEmail\` that sends an email to the customer → Weird; not a major responsibility of the customer → ==not cohesive + `, + }, ], }); diff --git a/src/rules/remove-multiple-spaces.ts b/src/rules/remove-multiple-spaces.ts index cc17378f..d446a3e1 100644 --- a/src/rules/remove-multiple-spaces.ts +++ b/src/rules/remove-multiple-spaces.ts @@ -1,7 +1,8 @@ import {Options, RuleType} from '../rules'; import RuleBuilder, {ExampleBuilder, OptionBuilderBase} from './rule-builder'; import dedent from 'ts-dedent'; -import {IgnoreTypes} from '../utils/ignore-types'; +import {ignoreListOfTypes, IgnoreTypes} from '../utils/ignore-types'; +import {updateListItemText} from '../utils/mdast'; class RemoveMultipleSpacesOptions implements Options {} @@ -19,7 +20,13 @@ export default class RemoveMultipleSpaces extends RuleBuilder)([^\s])( ){2,}([^\s])/gm, '$1 $3'); + text = ignoreListOfTypes([IgnoreTypes.list], text, (text: string): string => { + return text.replace(/(?!^>)([^\s])( ){2,}([^\s])/gm, '$1 $3'); + }); + + text = updateListItemText(text, (text: string): string => { + return text.replace(/([^\s])( ){2,}([^\s])/gm, '$1 $3'); + }); return text; }