Repository: platers/obsidian-linter (ts)

Issue:
FR: Ensure single space after blockquote `>` angle brackets
## Is Your Feature Request Related to a Problem? Please Describe.

I have one small issue I've just noticed related to blockquotes and our conversations in (#910). Not sure if it's intentional or not, and apologies if it has already been mentioned:

```markdown
>  Text
```

Doesn't lint as:

```markdown
> Text
```

Is there a reason why the >=2 spaces don't get reformatted as a single space? Maybe it's a compromise of some sort? Perhaps it's because not all people use spaces after blockquote angle brackets, e.g. `>> Text` or even `>>Text`.

The problem exists with plain lines beginning with a space too which lead me to find your options to "Remove space around/before/after characters". These could probably mitigate it (but as noted, whilst also risking Markdown formatting in some cases).

I mentioned a similar issue with tables, unsure if any relation: #951

## Describe the Solution You'd Like

I guess my only issue then is that maybe removing >1 spaces could be a distinct rule for blockquotes since we already have the "Space after list markers" option.

Consider adding "Space after _blockquote_ markers" to ensure a single space. Or more flexibly, make it a choice between ensuring no spaces (e.g. `>Text`), no spaces but one after final `>` (e.g. `>> Text`), and ensure space after each `>` (e.g. `> > Text`). If a blockquote `>` is followed by only whitespace, "Removes extra spaces after every line." should trim it.

You've recently done a lot to fix blockquote issues, so I don't expect you to be too enthusiastic at this time, but this issue is here for if/when that time comes.

Thanks!

Pull request:
Make Sure `Blockqoute Style` Gets Rid of Multiple Spaces for Blockquote Indicators when Set to `Space`
Fixes #961 

The logic for `Blockquote Style` was only adding missing spaces when the style was `Space`. This changes that to make it so that multiple spaces/tabs get cut down to just 1 space.

Changes Made:
- Added tests for multiple spaces, tabs, and a combination of spaces and tabs
- Added regex to take blockquote indicators followed by 2 or more spaces and or 1 or more tabs down to 1 space
- Fixed a bug with offsetting new line character positioning based on start of line differences in sizes that only mattered when nesting had lots of characters and text was small

Patch:
diff --git a/src/rules/blockquote-style.ts b/src/rules/blockquote-style.ts
index ce71a3d..37c2cfa 100644
--- a/src/rules/blockquote-style.ts
+++ b/src/rules/blockquote-style.ts
@@ -42,7 +42,7 @@ export default class BlockquoteStyle extends RuleBuilder<BlockquoteStyleOptions>
   addSpaceToIndicator(startOfLine: string): string {
     // first we add spaces to blockquote indicators that are not followed by a space and then to catch any that were not handled already
     // we make sure to add a space between any 2 indicators that are side by side
-    return startOfLine.replace(/>([^ \t]|$)/g, '> $1').replace(/>>/g, '> >');
+    return startOfLine.replace(/>([^ \t]|$)/g, '> $1').replace(/>>/g, '> >').replace(/>(?:[ \t]{2,}|\t+)/g, '> ');
   }
   updateBlockquoteLines(blockquote: string, startOfLineModification: (startOfLine: string) => string): string {
     let currentIndex = 0;
@@ -67,7 +67,7 @@ export default class BlockquoteStyle extends RuleBuilder<BlockquoteStyleOptions>
 
       newBlockquote = replaceTextBetweenStartAndEndWithNewValue(newBlockquote, startOfIndex, startOfIndex + startOfLine.length, updatedStartOfLine);
 
-      currentIndex = nextNewLine+ 1 + startOfLine.length - updatedStartOfLine.length;
+      currentIndex = nextNewLine+ 1 + updatedStartOfLine.length - startOfLine.length;
     } while (!breakOutOfLoop);
 
     return newBlockquote;


Test patch:
diff --git a/__tests__/blockquote-style.test.ts b/__tests__/blockquote-style.test.ts
index 8596677..fccf64f 100644
--- a/__tests__/blockquote-style.test.ts
+++ b/__tests__/blockquote-style.test.ts
@@ -29,5 +29,21 @@ ruleTest({
       `,
       options: {style: 'no space'},
     },
+    { // accounts for https://github.com/platers/obsidian-linter/issues/961
+      testName: 'Multiple spaces after a blockquote indicator is converted into one space',
+      before: dedent`
+        >   Text here
+        >     >           More Text Here
+        > \t > \t\t\t >Some More Text
+        >>>>\tJust a Tab
+      `,
+      after: dedent`
+        > Text here
+        > > More Text Here
+        > > > Some More Text
+        > > > > Just a Tab
+      `,
+      options: {style: 'space'},
+    },
   ],
 });