Repository: platers/obsidian-linter (ts)

Issue:
"First Letter" Capitalize headings option not working as expected
The "Capitalize Headings" option for formatting headings with the style "First Letter" works by *only* changing the first letter to upper case if it is lower case, however I would have expected this to also remove capitalization from words other than the first word. Example:

```
# this Is A Heading
```

Output:

```
# This Is A Heading
```

Expected output:

```
# This is a heading
```

I'm not sure if this is an intentional feature or a bug, but if it is intentional maybe there could be an additional option to format it the expected way? Thanks.

Pull request:
Fix capitalize heading first letter only
Fixes #145 

Patch:
diff --git a/src/rules.ts b/src/rules.ts
index c24c0df..a11d07b 100644
--- a/src/rules.ts
+++ b/src/rules.ts
@@ -897,7 +897,8 @@ export const rules: Rule[] = [
                 lines[i] = lines[i].toUpperCase(); // convert full heading to uppercase
                 break;
               case 'First Letter':
-                lines[i] = lines[i].replace(/^#*\s([a-z])/, (string) => string.toUpperCase()); // capitalize first letter of heading
+                lines[i] = lines[i].toLowerCase()
+                    .replace(/^#*\s([a-z])/, (string) => string.toUpperCase()); // capitalize first letter of heading
                 break;
             }
           }


Test patch:
diff --git a/src/test.ts b/src/test.ts
index 4052adb..c9b00cb 100644
--- a/src/test.ts
+++ b/src/test.ts
@@ -188,6 +188,24 @@ describe('Rules tests', () => {
         `;
       expect(rulesDict['capitalize-headings'].apply(before, {'Style': 'Title Case'})).toBe(after);
     });
+    it('Can capitalize only first letter', () => {
+      const before = dedent`
+        # this Is A Heading
+        `;
+      const after = dedent`
+        # This is a heading
+        `;
+      expect(rulesDict['capitalize-headings'].apply(before, {'Style': 'First Letter'})).toBe(after);
+    });
+    it('Can capitalize to all caps', () => {
+      const before = dedent`
+        # this Is A Heading
+        `;
+      const after = dedent`
+        # THIS IS A HEADING
+        `;
+      expect(rulesDict['capitalize-headings'].apply(before, {'Style': 'All Caps'})).toBe(after);
+    });
   });
   describe('File Name Heading', () => {
     it('Handles stray dashes', () => {