Skip to content

Commit

Permalink
Merge pull request #1207 from pjkaufman/master
Browse files Browse the repository at this point in the history
Fix `Remove Multiple Spaces` Removing Proceeding Spaces when Nested/Indented List Items Are Present in a Nested Blockquote/Callout
  • Loading branch information
pjkaufman authored Oct 25, 2024
2 parents 9769358 + ed3c3fe commit baea67f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
29 changes: 29 additions & 0 deletions __tests__/remove-multiple-spaces.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
`,
},
],
});

11 changes: 9 additions & 2 deletions src/rules/remove-multiple-spaces.ts
Original file line number Diff line number Diff line change
@@ -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 {}

Expand All @@ -19,7 +20,13 @@ export default class RemoveMultipleSpaces extends RuleBuilder<RemoveMultipleSpac
return RemoveMultipleSpacesOptions;
}
apply(text: string, options: RemoveMultipleSpacesOptions): string {
text = text.replace(/(?!^>)([^\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;
}
Expand Down

0 comments on commit baea67f

Please sign in to comment.