Repository: platers/obsidian-linter (ts)

Issue:
Bug: Indentations for math block removed from callouts or block quotes
- [x] I have verified that I am on the latest version of the Linter

## Describe the Bug

Hello,

When using math blocks with sublists in a callout or block quote, the indentations for math blocks are removed, which causes the list to be rendered incorrectly. Please see code blocks and screenshots bellow. From a quick search through the issues, I think this might be related to [#289](https://github.com/platers/obsidian-linter/issues/289).

Thanks in advance for the help, and also thanks for maintaining this awesome plugin :)


## How to Reproduce

Example to reproduce the issue with

``` markdown
>[!INFO] Linter sublist latex repro
> text
> - list item 1
>     $$
>     f = ma
>     $$
>     - sublist item 1
>         $$
>         y = ax + b
>         $$
```

On lint, this gets converted to

``` markdown
> [!INFO] Linter sublist latex repro
> text
> - list item 1
> $$
> f = ma
> $$
>     - sublist item 1
> $$
> y = ax + b
> $$
```

Please see my [data.json](https://github.com/platers/obsidian-linter/files/15213830/data.json).

## Expected Behavior

I'm actually not sure what the proper format for using math blocks in lists is, but I expected at least some indentation instead of completely removing them on lint.

The expected output should be should be the same (or similar) as the input

``` markdown
>[!INFO] Linter sublist latex repro
> text
> - list item 1
>     $$
>     f = ma
>     $$
>     - sublist item 1
>         $$
>         y = ax + b
>         $$
```

## Screenshots

Before linting
![Screenshot 2024-05-05 at 1 18 49 PM](https://github.com/platers/obsidian-linter/assets/16347901/a11e4b6e-fb50-4fd4-bf03-8ca6dcad7706)

After linting
![Screenshot 2024-05-05 at 1 19 13 PM](https://github.com/platers/obsidian-linter/assets/16347901/dc051aea-67f1-4aa0-b92f-83006f35755a)


## Device

- [x] Desktop
- [ ] Mobile


## Additional Context

Add any other context about the problem here.


Pull request description:
Fix: `blockquote-style` Removes Spaces from List Item Code and Math Blocks
Fixes #1087 

There was a reported bug where running the Linter would remove whitespace from list item math blocks. It was found that this also affected code blocks. In order to fix this, `blockquote-style` now ignores code and math block lines in blockquotes.

Changes Made:
- Added UTs for the scenarios in question
- Fixed a broken UT since we could no longer support the way things were done previously
- Updated logic to ignore math and code blocks when in a blockquote

Patch:
diff --git a/src/rules/blockquote-style.ts b/src/rules/blockquote-style.ts
index 355c07a..41850bb 100644
--- a/src/rules/blockquote-style.ts
+++ b/src/rules/blockquote-style.ts
@@ -20,7 +20,7 @@ export default class BlockquoteStyle extends RuleBuilder<BlockquoteStyleOptions>
       descriptionKey: 'rules.blockquote-style.description',
       type: RuleType.CONTENT,
       hasSpecialExecutionOrder: true, // to make sure we run after the other rules to make sure all blockquotes are affected and follow the same style
-      ruleIgnoreTypes: [IgnoreTypes.html, IgnoreTypes.code],
+      ruleIgnoreTypes: [IgnoreTypes.html, IgnoreTypes.code, IgnoreTypes.math],
     });
   }
   get OptionsClass(): new () => BlockquoteStyleOptions {
@@ -79,9 +79,16 @@ export default class BlockquoteStyle extends RuleBuilder<BlockquoteStyleOptions>
       }
 
       const restOfLine = newBlockquote.substring(startOfRestOfLine, endOfRestOfLine);
+      // we need to ignore code and math blocks to prevent changing values in the display
+      if (restOfLine.includes(IgnoreTypes.math.placeholder) || restOfLine.includes(IgnoreTypes.code.placeholder)) {
+        currentIndex++;
+        continue;
+      }
+
       const isListItemMarker = startsWithListMarkerRegex.test(restOfLine);
       updatedStartOfLine = startOfLineModification(startOfLine, isListItemMarker);
 
+
       // since start of index refers to where the new line character is
       startOfIndex++;
 


Test patch:
diff --git a/__tests__/blockquote-style.test.ts b/__tests__/blockquote-style.test.ts
index 7ca1a79..ab1594b 100644
--- a/__tests__/blockquote-style.test.ts
+++ b/__tests__/blockquote-style.test.ts
@@ -102,7 +102,7 @@ ruleTest({
       before: dedent`
         > Example blockquote
         >Wrongly indented line
-        > 
+        >
         >\`\`\`javascript
         > function greet() {
         >     console.log("Hello mom!")
@@ -112,8 +112,8 @@ ruleTest({
       after: dedent`
         > Example blockquote
         > Wrongly indented line
-        > 
-        > \`\`\`javascript
+        > ${''}
+        >\`\`\`javascript
         > function greet() {
         >     console.log("Hello mom!")
         > }
@@ -121,5 +121,61 @@ ruleTest({
       `,
       options: {style: 'space'},
     },
+    { // accounts for https://github.com/platers/obsidian-linter/issues/1087
+      testName: 'Math blocks in a blockquote should not have their spacing affected since that can remove indentation for lists',
+      before: dedent`
+        >[!INFO] Linter sublist latex repro
+        > text
+        > - list item 1
+        >     $$
+        >     f = ma
+        >     $$
+        >     - sublist item 1
+        >         $$
+        >         y = ax + b
+        >         $$
+      `,
+      after: dedent`
+        > [!INFO] Linter sublist latex repro
+        > text
+        > - list item 1
+        >     $$
+        >     f = ma
+        >     $$
+        >     - sublist item 1
+        >         $$
+        >         y = ax + b
+        >         $$
+      `,
+      options: {style: 'space'},
+    },
+    { // accounts for https://github.com/platers/obsidian-linter/issues/1087
+      testName: 'Code blocks in a blockquote should not have their spacing affected since that can remove indentation for lists',
+      before: dedent`
+        >[!INFO] Linter sublist code repro
+        > text
+        > - list item 1
+        >     \`\`\`
+        >     f = ma
+        >     \`\`\`
+        >     - sublist item 1
+        >         \`\`\`
+        >         y = ax + b
+        >         \`\`\`
+      `,
+      after: dedent`
+        > [!INFO] Linter sublist code repro
+        > text
+        > - list item 1
+        >     \`\`\`
+        >     f = ma
+        >     \`\`\`
+        >     - sublist item 1
+        >         \`\`\`
+        >         y = ax + b
+        >         \`\`\`
+      `,
+      options: {style: 'space'},
+    },
   ],
 });