Repository: platers/obsidian-linter (ts)

Issue:
Bug: Indentation Removed from Lists Nested in Block Quote or Callout
## Describe the Bug

Linter destroys legitimately formatted multi-level unordered lists within quote blocks & callouts

## How to Reproduce

1. Create an unordered list with multiple indentation levels.
2. Add '>' to the beginning of the lines to create a quote block or callout
3. Run linter.
4. Observe that the whitespace between '>' and '-' used to create the multiple levels of the list has been collapsed, and the list is no longer multi-level.

## Expected Behavior

Linter should ignore spaces between a '>' at the beginning of the line and '-' regardless of the rules selected.

## Screenshots

![2022-07-15_13-36-56](https://user-images.githubusercontent.com/1509989/179279370-0077d80a-0efd-4b71-84e3-bf3c74b84654.gif)

## Device

- [x] Desktop
- [ ] Mobile

[data.json.txt](https://github.com/platers/obsidian-linter/files/9122892/data.json.txt)



Pull request description:
Ignore Multiple Spaces at Start of Block Quote and Callouts
Fixes #289 

Made sure to keep indentation formatting at the start of a callout or block quote to prevent breaking things like code and indented lists in them.

Changes Made:
- Updated regex to ignore a callout or block quote at the start of a line
- Added tests to make sure that the callout and block quotes do not accidentally have their formatting removed at the start of the content on the line

Patch:
diff --git a/src/rules.ts b/src/rules.ts
index 7a7229a..3abd88d 100644
--- a/src/rules.ts
+++ b/src/rules.ts
@@ -644,7 +644,7 @@ export const rules: Rule[] = [
       RuleType.CONTENT,
       (text: string) => {
         return ignoreListOfTypes([IgnoreTypes.table, IgnoreTypes.code, IgnoreTypes.yaml, IgnoreTypes.link, IgnoreTypes.wikiLink, IgnoreTypes.tag], text, (text) => {
-          return text.replace(/([^\s])( ){2,}([^\s])/g, '$1 $3');
+          return text.replace(/(?!^>)([^\s])( ){2,}([^\s])/gm, '$1 $3');
         });
       },
       [


Test patch:
diff --git a/src/test/remove-multiple-spaces.test.ts b/src/test/remove-multiple-spaces.test.ts
index e77b9ed..2cd686e 100644
--- a/src/test/remove-multiple-spaces.test.ts
+++ b/src/test/remove-multiple-spaces.test.ts
@@ -94,6 +94,93 @@ describe('Remove Multiple Spaces', () => {
       New paragraph.
       `;
 
+    expect(rulesDict['remove-multiple-spaces'].apply(before)).toBe(after);
+  });
+  // accounts for https://github.com/platers/obsidian-linter/issues/289
+  it('Callouts and block quotes allow multiple spaces at start to allow for code and list item indentation', () => {
+    const before = dedent`
+      # List Item in Callout
+        
+      > [!info] Unordered List
+      > - First Level
+      > - First Level
+      >   - Second Level
+      >     - Third Level
+      > - First Level
+
+      # Code in Callout
+
+      > [!info] Code
+      >     Line 1
+      >     Line 2
+      >     Line 3
+
+      # List Item in Block Quote
+        
+      > Unordered List
+      > - First Level
+      > - First Level
+      >   - Second Level
+      >     - Third Level
+      > - First Level
+
+      # Code in Block Quote
+      
+      > Code
+      >     Line 1
+      >     Line 2
+      >     Line 3
+    `;
+
+    const after = dedent`
+      # List Item in Callout
+        
+      > [!info] Unordered List
+      > - First Level
+      > - First Level
+      >   - Second Level
+      >     - Third Level
+      > - First Level
+
+      # Code in Callout
+
+      > [!info] Code
+      >     Line 1
+      >     Line 2
+      >     Line 3
+
+      # List Item in Block Quote
+        
+      > Unordered List
+      > - First Level
+      > - First Level
+      >   - Second Level
+      >     - Third Level
+      > - First Level
+
+      # Code in Block Quote
+      
+      > Code
+      >     Line 1
+      >     Line 2
+      >     Line 3
+    `;
+
+    expect(rulesDict['remove-multiple-spaces'].apply(before)).toBe(after);
+  });
+  it('Multiple spaces after ">" are still removed if not the start of a line', () => {
+    const before = dedent`
+    # Text with > with multiple spaces after it
+      
+    Text >  other text
+    `;
+
+    const after = dedent`
+    # Text with > with multiple spaces after it
+      
+    Text > other text
+    `;
+
     expect(rulesDict['remove-multiple-spaces'].apply(before)).toBe(after);
   });
 });