Repository: platers/obsidian-linter (ts)

Issue:
Bug: Empty Line Around Tables not respected
## Describe the Bug

"Empty Line Around Tables" option is enabled in Linter  but when the command is ran it removes all empty lines between a Header and the table

## How to Reproduce

Steps to reproduce the behavior:

1. Enable "Empty Line Around Tables"
2. In a document (not beginning or end) create a H2, create an empty line and add a table after the header
3. Run Linter
4. Empty line between H2 and table is removed and table is not rendered properly

Example to reproduce issue with

``` markdown
## Logical operators

| Operator | Meaning                  | Example               |
|----------|--------------------------|-----------------------|
|`==`| Is Equal To              | 3 == 5 gives us False |
|`!=`| Not Equal To             | 3 != 5 gives us True  |
|`>`| Greater Than             | 3 > 5 gives us False  |
|`<` | Less Than                | 3 < 5 gives us True   |
|`>=`| Greater Than or Equal To | 3 >= 5 give us False  |
|`<=`|Less Than or Equal To|3 <= 5 gives us True |
```

#### Log
Running linter
Running Format Tags in YAML
Running Format Yaml Array
Running Move Tags to Yaml
Running Remove Trailing Punctuation in Heading
Running Convert Bullet List Markers
Running Remove Consecutive List Markers
Running Remove Empty List Markers
Running Remove Hyphenated Line Breaks
Running Remove Multiple Spaces
Running Two Spaces Between Lines with Content
Running Compact YAML
Running Consecutive blank lines
Running Empty Line Around Blockquotes
Running Empty Line Around Code Fences
Running Empty Line Around Math Blocks
Running Empty Line Around Tables
Running Heading blank lines
Running Remove Empty Lines Between List Markers and Checklists
Running Remove link spacing
Running Space after list markers
Running Trailing spaces
Running Custom Regex
Running Capitalize Headings
Running Custom Lint Commands

## Expected Behavior
There should be one empty line between the H2 and the table

## Screenshots

Before
![image](https://github.com/platers/obsidian-linter/assets/66655064/df5099aa-ed76-4944-b33a-92f78ce739ed)

After
![image](https://github.com/platers/obsidian-linter/assets/66655064/7ab67e9d-1cd5-44dc-a180-869e968b3a1d)

## Device

- [ x] Desktop
- [ ] Mobile



Pull request description:
Fix `Heading Blank Lines` with `Bottom=False` Removing Blank Lines
Fixes #751 
Replaces #755 

Changes Made:
- Added a UT for not removing blank lines after a heading
- Updated logic to remove the attempt to remove blank lines after the heading

Patch:
diff --git a/src/rules/heading-blank-lines.ts b/src/rules/heading-blank-lines.ts
index da3fedd..8a4450b 100644
--- a/src/rules/heading-blank-lines.ts
+++ b/src/rules/heading-blank-lines.ts
@@ -24,7 +24,6 @@ export default class HeadingBlankLines extends RuleBuilder<HeadingBlankLinesOpti
   }
   apply(text: string, options: HeadingBlankLinesOptions): string {
     if (!options.bottom) {
-      text = text.replace(/(^#+\s.*)\n+/gm, '$1\n'); // trim blank lines after headings
       text = text.replace(/\n+(#+\s.*)/g, '\n\n$1'); // trim blank lines before headings
     } else {
       text = text.replace(/^(#+\s.*)/gm, '\n\n$1\n\n'); // add blank line before and after headings


Test patch:
diff --git a/__tests__/heading-blank-lines.test.ts b/__tests__/heading-blank-lines.test.ts
index db3b8a6..a37cfb4 100644
--- a/__tests__/heading-blank-lines.test.ts
+++ b/__tests__/heading-blank-lines.test.ts
@@ -103,5 +103,29 @@ ruleTest({
         blah blah blah
       `,
     },
+    { // accounts for https://github.com/platers/obsidian-linter/issues/751
+      testName: 'Make sure that blank lines after a heading are left alone when `bottom = false`',
+      before: dedent`
+        ## diary
+        ${''}
+        ${''}
+        Content here
+        ## entry 2
+        blah blah blah
+      `,
+      after: dedent`
+        ## diary
+        ${''}
+        ${''}
+        Content here
+        ${''}
+        ## entry 2
+        blah blah blah
+      `,
+      options: {
+        bottom: false,
+        emptyLineAfterYaml: false,
+      },
+    },
   ],
 });